By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

sql error message

P: 29
Hi
I have been trying to run this code, and what it is doing is inserting records into a table called tblRequestByService. the values that it is inserting are taken from the form itslef (They are normal text boxes). every time i click the button to do that, i get the folling error message:

"Number Of Query Values and Destination Fields are not the same". I have been having similar problems throughout. i know that the number of fields that i am inserting is the same number of fields on the actual table.

This is the code that i hjave been using.

Dim strSQL As String

strSQL = "INSERT INTO [tblRequestByService]([Serviced Requested], [Service Provider], [Requested By], [Start Date], [Duration]) " & _
"VALUES (forms![frmSearchService].[txtForService], forms![frmSearchService].[txtServiceProvidedBy], forms![frmSearchService].[txtRequestBy], forms![frmSearchService].[txtRequiredDate], forms![frmSearchService].[txtDuration],1);"
DoCmd.RunSQL strSQL

End Sub



Please can anyone tell me how to solve this problem
Apr 18 '07 #1
Share this Question
Share on Google+
3 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
Your query has 5 fields and 6 values. Remove the ",1" from the end of the statement as follows:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = "INSERT INTO [tblRequestByService] " & _
  4.    "([Serviced Requested], [Service Provider], [Requested By], [Start Date], [Duration]) " & _
  5.    "VALUES (forms![frmSearchService].[txtForService], forms![frmSearchService].[txtServiceProvidedBy], " & _
  6.    "forms![frmSearchService].[txtRequestBy], forms![frmSearchService].[txtRequiredDate], " & _
  7.    "forms![frmSearchService].[txtDuration]);"
  8. DoCmd.RunSQL strSQL
  9.  
  10. End Sub
  11.  
Mary
Apr 18 '07 #2

P: 29
thanks.

I am also trying to open up a from in add mode, from another form.
i have one form, and wen u click a button, it should take you to another form (from a different base table), and open that up in add mode.
I have tried a few several ways, but it doesn't work.
How is the solved
Apr 18 '07 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
thanks.

I am also trying to open up a from in add mode, from another form.
i have one form, and wen u click a button, it should take you to another form (from a different base table), and open that up in add mode.
I have tried a few several ways, but it doesn't work.
How is the solved
This will open a form in Add mode
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "FormName", , , , acFormAdd
Apr 18 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.