How can I use a ListBox.Value as criteria for DoCmd.FindRecord?
How can I use a ListBox.Value as criteria for DoCmd.FindRecord?

This month, every Windows Secrets subscriber can download a one-chapter excerpt of Windows 7: The Missing Manual.Windows 7: The Missing Manual provides valuable information to help you overcome these difficulties in learning a new operating system. Subscribe today to download your free excerpt.
One way to do this is to use the BuildCriteria() Function that is in Access. Here is an example:
Private Sub cboYourComboName_AfterUpdate()
On Error GoTo ErrorHandler
If Not IsNull(cboYourComboName) Then
Me.RecordsetClone.FindFirst BuildCriteria("NameOfFieldInTable", dbText, cboYourComboName)
Me.Bookmark = Me.RecordsetClone.Bookmark
cboYourComboName = Null
Else
MsgBox "You Must Choose a Value from the ComboBox.", vbOKOnly, " No Item Selected ...."
End If
ExitHere:
Exit Sub
ErrorHandler:
MsgBox Err.Description
Resume ExitHere
End Sub
You can find more information on the use of this function in Access Help files.
HTH
RDH
Ricky Hicks
Microsoft MVP
Birmingham, Alabama USA
One caveat on BuildCriteria is that it only handles a single field at a time. If you want two different criteria (i.e., Field1 = "OK" And Field2 > 3), you'll have to run BuildCriteria twice and join the results. I always forget about the function because by the time you type in all the pieces, you might as well have created the criteria string by hand. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
Charlotte
You are absolutely right .....
I just thought I'd mention it due to many people not knowing that this function exists.
Happy Holidays,
RDH
Ricky Hicks
Microsoft MVP
Birmingham, Alabama USA
Works Great, Thanks and Merry Christmas
Great .... You are Welcome .... <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
Make sure you read Charlotte's note about the limations of using this function.
Happy Holidays,
RDH
Ricky Hicks
Microsoft MVP
Birmingham, Alabama USA