Open specific record - Syntax

testdba

Registered User.
Local time
Yesterday, 23:07
Joined
Dec 16, 2004
Messages
26
I am trying to use the double click event of a listbox to open a form to a specific record. The problem I have is when I double click a record, Access pops up a box asking for PONumber (which is in column 0 of the listbox).

Here is the code that I am using:

Code:
Private Sub lstPOInfo_DblClick(Cancel As Integer)

Dim boStatus As Boolean
Dim strDocName As String
Dim strLinkCriteria As String

    strDocName = "Orders"

    ' function checks to see if the form is open or not
    boStatus = fIsLoaded(strDocName) 
    
    If boStatus = True Then
       strLinkCriteria = "[PONumber]=" & Me.lstPOInfo.Column(0)
       
       Forms![Orders].FilterOn = True
       Forms![Orders].Filter = strLinkCriteria
        
    Else
        strLinkCriteria = "[PONumber]=" & Me.lstPOInfo.Column(0)
        DoCmd.OpenForm strDocName, , , strLinkCriteria
    End If
    
End Sub

I'm sure it's a syntax error on the "strLinkCriteria = "[PONumber]=" & Me.lstPOInfo.Column(0)" line.
 
Last edited:
try removing
"[PONumber]=" &
 
wazz said:
try removing
"[PONumber]=" &

I tried it without "[PONumber]=" & and it still opens the box and it no longer links opens the correct record.
 
Eureka!

I found it. I looked back through some old posts and databases that I had and found something that was closely related. I don't understand the syntax, but it works. I changed the line to strLinkCriteria = "[PONumber]= '" & Me.lstPOInfo.Column(0) & "'".

Here is the working code:
Code:
Private Sub lstPOInfo_DblClick(Cancel As Integer)

Dim boStatus As Boolean
Dim strDocName As String
Dim strLinkCriteria As String

    strDocName = "Orders"
    boStatus = fIsLoaded(strDocName)
    
    If boStatus = True Then
       strLinkCriteria = "[PONumber]= '" & Me.lstPOInfo.Column(0) & "'"
       
       Forms![Orders].Filter = strLinkCriteria
       Forms![Orders].FilterOn = True
        
    Else
        strLinkCriteria = "[PONumber]= '" & Me.lstPOInfo.Column(0) & "'"
        DoCmd.OpenForm strDocName, , , strLinkCriteria
    End If
    
End Sub

Thanks for your help! :)

P.S. I did switch the two filter lines around Pat. :)
 
Last edited:

Users who are viewing this thread

Back
Top Bottom