D
dubbglubb
Hello Everybody,
Having a spot of bother with SQL and DAO. If this belongs in another
forum please tell me, but since I'm working in word, here I am.
I've created a Userform (GymyDoc) in Word with a TextBox (txtOurRef).
I'd like the user to be able to enter a -document number -e.g 84171,
and return text into the other TextBoxes.
Curently I can get is to work only by hardcoding the number into the
SQL eg:
Code:
--------------------
Set rstJob = dbEML.OpenRecordset("SELECT [Client], [Suburb], [State], [Zip], [Nata] FROM [tblGymy]" _
& "WHERE [Document No] = 84171 ")
--------------------
Ideally I'd replace the number with a variable
Code:
--------------------
varOurRef = txtOurRef.Text
--------------------
But I just can't get the syntax right. I get get various errors. This
version uses the full reference to the txtOurRef, but I'd like to
replace with varOurRef if I can.
Code:
--------------------
Dim dbEML As Database, rstJob As Recordset
Private Sub cmdGetDatabase_click()
Set dbEML = OpenDatabase("F:\ADMINISTRATION\DATABASE\EML DATABASE\EMLAIR.MDB")
Set rstJob = dbEML.OpenRecordset("SELECT [Client], [Suburb], [State], [Zip], [Nata] FROM [tblGymy]" _
& "WHERE [Document No] = '" & Forms!GymyDoc!txtOurRef.Text & "'")
FillFields
End Sub
Private Sub FillFields()
txtClient.Text = rstJob.Fields("Client")
lblNata.Caption = rstJob.Fields("Nata")
txtSuburb.Text = rstJob.Fields("Suburb")
txtClientState.Text = rstJob.Fields("State")
txtPostCode.Text = rstJob.Fields("Zip")
End Sub
--------------------
Any Ideas?
Cheers
Having a spot of bother with SQL and DAO. If this belongs in another
forum please tell me, but since I'm working in word, here I am.
I've created a Userform (GymyDoc) in Word with a TextBox (txtOurRef).
I'd like the user to be able to enter a -document number -e.g 84171,
and return text into the other TextBoxes.
Curently I can get is to work only by hardcoding the number into the
SQL eg:
Code:
--------------------
Set rstJob = dbEML.OpenRecordset("SELECT [Client], [Suburb], [State], [Zip], [Nata] FROM [tblGymy]" _
& "WHERE [Document No] = 84171 ")
--------------------
Ideally I'd replace the number with a variable
Code:
--------------------
varOurRef = txtOurRef.Text
--------------------
But I just can't get the syntax right. I get get various errors. This
version uses the full reference to the txtOurRef, but I'd like to
replace with varOurRef if I can.
Code:
--------------------
Dim dbEML As Database, rstJob As Recordset
Private Sub cmdGetDatabase_click()
Set dbEML = OpenDatabase("F:\ADMINISTRATION\DATABASE\EML DATABASE\EMLAIR.MDB")
Set rstJob = dbEML.OpenRecordset("SELECT [Client], [Suburb], [State], [Zip], [Nata] FROM [tblGymy]" _
& "WHERE [Document No] = '" & Forms!GymyDoc!txtOurRef.Text & "'")
FillFields
End Sub
Private Sub FillFields()
txtClient.Text = rstJob.Fields("Client")
lblNata.Caption = rstJob.Fields("Nata")
txtSuburb.Text = rstJob.Fields("Suburb")
txtClientState.Text = rstJob.Fields("State")
txtPostCode.Text = rstJob.Fields("Zip")
End Sub
--------------------
Any Ideas?
Cheers