Help with vba

C

C Tate

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.
 
D

Dennis

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)
 
C

C Tate

Brilliant! Thanks so much

Dennis said:
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)

C Tate said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top