Inserting specific field from a form into a specific table (1 Viewer)

Naqibullah

Registered User.
Local time
Today, 23:06
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
 

JHB

Have been here a while
Local time
Today, 20:36
Joined
Jun 17, 2012
Messages
7,732
And the error message is?
 

Naqibullah

Registered User.
Local time
Today, 23:06
Joined
Feb 7, 2013
Messages
86
It says, me.vslaid and me.memberid is not recognized.
 

sneuberg

AWF VIP
Local time
Today, 11:36
Joined
Oct 17, 2014
Messages
3,506
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:

Naqibullah

Registered User.
Local time
Today, 23:06
Joined
Feb 7, 2013
Messages
86
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.
 

sneuberg

AWF VIP
Local time
Today, 11:36
Joined
Oct 17, 2014
Messages
3,506
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?
 

Naqibullah

Registered User.
Local time
Today, 23:06
Joined
Feb 7, 2013
Messages
86
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.
 

JHB

Have been here a while
Local time
Today, 20:36
Joined
Jun 17, 2012
Messages
7,732
.. 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.
 

Naqibullah

Registered User.
Local time
Today, 23:06
Joined
Feb 7, 2013
Messages
86
Dear both,
thank you, for your guidance.
 
Last edited:

Tfa

Registered User.
Local time
Today, 21:36
Joined
Nov 29, 2016
Messages
32
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

Top Bottom