DoCmd.GoToRecord help needed

spnz

Registered User.
Local time
Today, 19:24
Joined
Feb 28, 2005
Messages
84
Hi there

I am making a form that has been set up to have a number of tabs so I can have more then 1 page on the form.

One of the tab pages is used as a search form.There is a couple of textboxes and a listbox where the results end up
What I am trying to do is have a double click set up on the listbox so I can double click the result I want and have the forms ID goto that record.

Its a bound form. The primary key is called PersonalID and its bound to a txtbox called txtPersonalID.

this is my code but its not working
Code:
Private Sub lstSearchResults_DblClick(Cancel As Integer)
        
    Dim strPersonalID As String
    strPersonalID = Me.lstSearchResults.Column(0)
    DoCmd.GoToRecord acActiveDataObject, "PersonalID", acGoTo, strPersonalID
    DoCmd.GoToControl "pgePersonalInformation"
    
End Sub

When I try run the code I get an error 2489. saying The object 'PersonalID' isn't open.

What am I doing wrong?

Can anyone help out

TIA
 
Code:
...
    strPersonalID = Me.lstSearchResults.Column(0)
...

How does it know what you've selected? You might want to think of using a combination of ItemsSelected and ItemData. Search for their syntax in Access VB.

Good Lucks
 
Thanks for the pointers Supercharge

Its great when you know what your looking for. Found the answer in MS help within minutes.

heres my updated code if anyone is interested.
Code:
Private Sub lstSearchResults_DblClick(Cancel As Integer)
        
    Dim ctlList As Control, varItem As Variant

    ' Return Control object variable pointing to list box.
    Set ctlList = Forms!frmMain!lstSearchResults
    ' Enumerate through selected items.
    For Each varItem In ctlList.ItemsSelected
        ' Print value of bound column.
        Debug.Print ctlList.ItemData(varItem)
      DoCmd.GoToRecord , , acGoTo, ctlList.ItemData(varItem)
  
    Next varItem
    
    
    
    
End Sub

Thanks again
 

Users who are viewing this thread

Back
Top Bottom