I am trying to create a listbox to search for records. The example I am using
is from www.databasedev.co.uk/list_box_searching.html.
I am using this code but it just will not work.
Private Sub ShowRecord_Click()
'Find a selected record, then close the search dialog box
DoCmd.OpenForm "frmSite", , , _
"[tblSite.siteID]=" & "'" & Me.FirstSearch.Column(0) & "'"
'Close the dialog box
DoCmd.Close acForm, "frmSearch"
End Sub
I note that their example is searching on a textfield whereas mine is
searching on an autonumber field. I cannot possibly imagine what I am doing
wrong. It seems to highlight the me.firstsearch.column(0) bit. I have named
the listbox firstsearch. Can access automatically work out column numbers? If
not, how do I name them? Any advice would be most helpful. Thanks.
Text fields require apostrophies around the text item whereas numbers do not,
so your code should look like this
DoCmd.OpenForm "frmSite", , , _
"[tblSite.siteID]=" & Me.FirstSearch.Column(0)
> I am trying to create a listbox to search for records. The example I am using
> is from www.databasedev.co.uk/list_box_searching.html.
[quoted text clipped - 16 lines]
> the listbox firstsearch. Can access automatically work out column numbers? If
> not, how do I name them? Any advice would be most helpful. Thanks.
C Tate - 20 May 2008 15:59 GMT
Brilliant! Thanks so much
> Text fields require apostrophies around the text item whereas numbers do not,
> so your code should look like this
[quoted text clipped - 22 lines]
> > the listbox firstsearch. Can access automatically work out column numbers? If
> > not, how do I name them? Any advice would be most helpful. Thanks.