Using input from form to run code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that the user will input a value like 0133232
I would lkie to use this to create a table
Excerpt of my code is
dim two as string
Me.Form.txtmatter.SetFocus
two = Me.Form.txtmatter.Text

pstrsql = "select * into tempreportdata from FINALMATTEREXCEPTION " & _
" where mrmatter = two "
db.Execute (pstrsql)

the SQL string does not recognize the variable "two"

so my where clause is mrmatter = two.

Any suggestions would be helpful.

thanks
 
You need to put the variable outside of the quotes:

pstrsql = "select * into tempreportdata from FINALMATTEREXCEPTION " & _
" where mrmatter = " & two

If mrmatter is a text field, you need to put quotes around whatever value is
in the variable.

pstrsql = "select * into tempreportdata from FINALMATTEREXCEPTION " & _
" where mrmatter = " & Chr$(34) & two & Chr$(34)
 
I have a form that the user will input a value like 0133232
I would lkie to use this to create a table
Excerpt of my code is
dim two as string
Me.Form.txtmatter.SetFocus
two = Me.Form.txtmatter.Text

pstrsql = "select * into tempreportdata from FINALMATTEREXCEPTION " & _
" where mrmatter = two "
db.Execute (pstrsql)

the SQL string does not recognize the variable "two"

so my where clause is mrmatter = two.

Any suggestions would be helpful.

thanks

Dim two as String
Dim pstrsql as String
two = Me!txtmatter
pstrsql = "select * into tempreportdata from FINALMATTEREXCEPTION " _
& " where mrmatter = '" & two & "';", dbFailOnError
db.Execute pstrsql

Just for clarity the where clause quotes are placed as follows:
.... where mrmatter = ' " & two & " ';"
 
Back
Top