0
votes

I have a form in access. I'm using VBA to enter the values into the table.

Problem:

"Too few parameters; Expected 1;" - I'm getting this error EVEN THOUGH THE TABLE COLUMN NAMES MATCHES WHAT IS IN THE INSERT STATEMENT.

Private Sub Command125_Click()
    Dim dbsCurrent As Database
    Set dbsCurrent = CurrentDb

    'add data to table production_date, reason, downtime_minutes, comment , Me.Text126, Me.Text121, Me.Text123, Me.Text128
    dbsCurrent.Execute " INSERT INTO tbl_Downtime " _
    & "(job) VALUES " _
    & "(dbsCurrent.Me.Text116);"

End Sub

End Goal:

First of all I want to fix this error. But I also need to be able to update the row based on the ID (auto-numbered in the table). How do I allow users to update the row if they know the ID of the row?

1
Please do yourself a favor and rename your controls like Command125 and Text116 to meaningful names. This really helps the readability of your code.Andre
I literally realized that after going through the headache of this question haha thankswhatwhatwhat

1 Answers

0
votes

The problem appears to be that you put quotation marks around your VBA reference to Text116. I assume "job" is a string. Try the following:

Private Sub Command125_Click()
Dim dbsCurrent As Database
Set dbsCurrent = CurrentDb

'add data to table production_date, reason, downtime_minutes, comment , Me.Text126, Me.Text121, Me.Text123, Me.Text128
dbsCurrent.Execute " INSERT INTO tbl_Downtime " _
& "('job') VALUES " _
& "('" & dbsCurrent.Text116 & "');"

End Sub