Inserting specific field from a form into a specific table

Naqibullah

Registered User.
Local time
Tomorrow, 03:18
Joined
Feb 7, 2013
Messages
86
Dear Colleagues,
Greetings!
i have a continues form which lists members of a specific group, from this form, i want to insert some members (one by one) into a specific table which i already designed, but when i run insert command, i received an error.

Private Sub Command34_Click()
Dim sSQL As String

Set sSQL = "INSERT INTO VSLAMembertbl (VSLAID,MemberID) VALUES (" & Me.VSLAID & "," & Me.MemberID & ");"
DoCmd.RunSQL sSQL

End Sub

thanks in advance from you answers
 
And the error message is?
 
It says, me.vslaid and me.memberid is not recognized.
 
Set is used to assign values to object variables and is not needed or valid when assigning to a string variable. Delete the Set and it should work if both values and fields (VSLAID and MemberID) are numeric.
 
Last edited:
Thank you both Respected JHB and respected sneuburg for your prompt response. kindly guide me a reference book on writing codes in access visual basic, i tried alot to learn writing access syntax. still i think i need to improve my coding skills in access visual basic. for instance in c or c++ or java i know the syntax but in access i don't know where to put double quote where to put single quote, where to put and sign (&). sorry if i am telling simple thinks.
 
You can download the VBA specification from this site. I also recommend viewing this video series. For specific information on concatenating variables into SQL look at this site.

Do you still have a problem with you INSERT statement code?
 
Thank you for your both solutions, i forgot to remark that your reply to insert query worked and i will follow the links you have directed me.
Sincere regards.
 
.. but in access i don't know where to put double quote where to put single quote, where to put and sign (&). sorry if i am telling simple thinks.
If you want to include a text value in a sting then you use a single quote.
Let's be based upon the SQL string you show, and let's say that Me.VSLAID is a text variable.
sSQL = "INSERT INTO VSLAMembertbl (VSLAID,MemberID) VALUES ('" & Me.VSLAID & "'," & Me.MemberID & ");"
The (&) signs are in the string you show correct, so I don't think it is so a big problem for you, else you need to be more specific what the problem is.
Also the help file in MS-Access could give you a lot of help.
 
Dear both,
thank you, for your guidance.
 
Last edited:
well i would suggest inserting through DAO
in case of Nulls or special chars you might have a problem later on
 

Users who are viewing this thread

Back
Top Bottom