trident2
asked on
VBA SQL doesn't recognise variable value
I'm just learning VBA so I'm sure there is a simple answer to this. I've got a form with abutton that fires a VBA procedure;
Option Compare Database
Private Sub yy_Click()
Dim strSQL As String
Static name As String
name = "ali"
strSQL = "INSERT INTO staff2 (NAME, PHONE) VALUES ( " & name & ", 02067737783)"
DoCmd.RunSQL (strSQL)
End Sub
When the button is clicked Access always pops a "Enter parameter value" box with the word 'ali' above an input field. If I type a value into the input box the query is successfuly completed.
However, I really want the query to insert the value of the variable 'name', and not to ask me to input a value. What am I doing wrong?
Cheers,
Ali
Option Compare Database
Private Sub yy_Click()
Dim strSQL As String
Static name As String
name = "ali"
strSQL = "INSERT INTO staff2 (NAME, PHONE) VALUES ( " & name & ", 02067737783)"
DoCmd.RunSQL (strSQL)
End Sub
When the button is clicked Access always pops a "Enter parameter value" box with the word 'ali' above an input field. If I type a value into the input box the query is successfuly completed.
However, I really want the query to insert the value of the variable 'name', and not to ask me to input a value. What am I doing wrong?
Cheers,
Ali
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
strSQL = "INSERT INTO staff2 (NAME, PHONE) VALUES ( " & "'"& name &"'" & ", 02067737783)"