Firstly, thanks in advance for any help.....
How do I look up a field (price) from another table whilst in a form, One table makes up the form, and the other table I need to reference, "price" , are linked by a "part no" field.
I need this to insert the price in the form.
I have had some help from Stephenk1973 (thanks ?) …
The code is
Private Sub Form_Current()
Dim sSQL As String
Dim Rec As Recordset
Dim db As Database
' Query to bring out the price, using variables in the form.
sSQL = "SELECT DISTINCT price FROM tblPrices "
sSQL = sSQL & "WHERE partno = '" & PartNo & "';"
Set db = CurrentDb
Set Rec = db.OpenRecordset(sSQL)
' Check something is returned and set the price field to returned value.
If Rec.RecordCount > 0 Then
Price = Rec("price"
Else
Price = "0"
End If
End Sub
When I open the form, I get a runtime error ‘3464’
Can anyone help.
Thanks
Allen
MCSE 2000, A+
When Confronted with a serious problem, you can solve it more easily by reducing it to the question, "How would the Lone Ranger handle this"?
How do I look up a field (price) from another table whilst in a form, One table makes up the form, and the other table I need to reference, "price" , are linked by a "part no" field.
I need this to insert the price in the form.
I have had some help from Stephenk1973 (thanks ?) …
The code is
Private Sub Form_Current()
Dim sSQL As String
Dim Rec As Recordset
Dim db As Database
' Query to bring out the price, using variables in the form.
sSQL = "SELECT DISTINCT price FROM tblPrices "
sSQL = sSQL & "WHERE partno = '" & PartNo & "';"
Set db = CurrentDb
Set Rec = db.OpenRecordset(sSQL)
' Check something is returned and set the price field to returned value.
If Rec.RecordCount > 0 Then
Price = Rec("price"
Else
Price = "0"
End If
End Sub
When I open the form, I get a runtime error ‘3464’
Can anyone help.
Thanks
Allen
MCSE 2000, A+
When Confronted with a serious problem, you can solve it more easily by reducing it to the question, "How would the Lone Ranger handle this"?