Open a form to a specific record

testdba

Registered User.
Local time
Today, 04:21
Joined
Dec 16, 2004
Messages
26
I have a form named frmProducts and on it there is a field for the name of the product supplier. Beside the supplier there is a button named cmdViewSupplierDetails that is supposed to open a form with the specific supplier's details. Somewhere on this board I found an example of this (the example was called DemoDetailsA97.mdb), but I'm having trouble getting it to work. This is the code on the view button:

Code:
Private Sub cmdViewSupplierDetails_Click()
On Error GoTo Err_cmdViewSupplierDetails_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmSuppliers"

    If IsNull(Me!SupplierName) Then
      MsgBox "Select a valid supplier."
      Exit Sub
    Else
      stLinkCriteria = "[SupplierName]=" & Me![SupplierName]
    End If
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdViewSupplierDetails_Click:
    Exit Sub
Err_cmdViewSupplierDetails_Click:
    MsgBox Err.Description
    Resume Exit_cmdViewSupplierDetails_Click
End Sub

The error I get when I click the button is: "Syntax error (missing operator) in query expression '[SupplierName]=test manufacturer'. (Test manufacturer is what is in the combo box labled "SupplierName".)

What do I have wrong? In the example database, the two connected fields were number fields and I am using two text fields, does that make the difference in the query syntax?

Thanks for the help.
-Tim
 
Tim:

Did you try using quotes for the string?

something like:
stLinkCriteria = "[SupplierName]= '" & Me![SupplierName] &"'"

Note that there is a single quote before the double quote...that way the WHERE condition will read like:

[SupplierName]= 'test manufacturer'

SHADOW
 
Good call!

Aha! You did it! I changed the line to:

stLinkCriteria = "[SupplierName]= '" & Me![SupplierName] &"'"

and it worked perfectly! Thanks for your help and speedy response! :D
 
Tim:

You are most welcome. I've received a great deal of help from this forum, and I'd love to share what I can with others.

SHADOW
 

Users who are viewing this thread

Back
Top Bottom