code error in subform - urgent your help

G

Guest

Hi there,

I have a main form and a subform, I trying a code in subform as below and
found a run-time error#3464 on the line of "Set rst =
db.OpenRecordset(strSQL)"

I am appreciate for your help in advance!!!!!

Private Sub LABOUR_NO_AfterUpdate()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String


Set db = CurrentDb
strSQL = "SELECT * from [LABOUR TABLE] WHERE [LABOUR NO]=" & Me![labour no]

Set rst = db.OpenRecordset(strSQL)


Me![SALARY] = rst![DAILY SALARY]

rst.Close

End Sub
 
G

Guest

It is a syntax problem:
If [LABOUR NO] is text field:
strSQL = "SELECT * from [LABOUR TABLE] WHERE [LABOUR NO]= '" & Me![labour
no] & "':"
If it is a numeric field:
strSQL = "SELECT * from [LABOUR TABLE] WHERE [LABOUR NO]= " & Me![labour no]
& ":"

Note: It is not a good practice to use spaces in names. A better name
would be LABOUR_NO
 
G

Guest

Hi Klatuu,

It is work now! Thanks so much!!!

Klatuu said:
It is a syntax problem:
If [LABOUR NO] is text field:
strSQL = "SELECT * from [LABOUR TABLE] WHERE [LABOUR NO]= '" & Me![labour
no] & "':"
If it is a numeric field:
strSQL = "SELECT * from [LABOUR TABLE] WHERE [LABOUR NO]= " & Me![labour no]
& ":"

Note: It is not a good practice to use spaces in names. A better name
would be LABOUR_NO

Andy said:
Hi there,

I have a main form and a subform, I trying a code in subform as below and
found a run-time error#3464 on the line of "Set rst =
db.OpenRecordset(strSQL)"

I am appreciate for your help in advance!!!!!

Private Sub LABOUR_NO_AfterUpdate()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String


Set db = CurrentDb
strSQL = "SELECT * from [LABOUR TABLE] WHERE [LABOUR NO]=" & Me![labour no]

Set rst = db.OpenRecordset(strSQL)


Me![SALARY] = rst![DAILY SALARY]

rst.Close

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top