Searching for records

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use an autonumber to identify records. Is there a way to use that field to
quickly search for records, much like you can enter the record number in
Access's build-in navigation tools to quickly jump to a desired record.
 
Place an unbound text box (or combo if there aren't too many records) on
your form (e.g. in the Form Header section).

Name it "Goto".

Set its AfterUpdate property to
[Event Procedure]

Click the Build button (...) beside this.
Access opens the code window.
Paste the following in between the "Private Sub..." and "End Sub" lines:

Dim strWhere As String
If Me.Dirty Then 'Save before move.
Me.Dirty = False
End If
If Not IsNull(Me.Goto) Then
strWhere = "[NameOfYourIDFieldHere] = " & Me.Goto
With Me.RecordsetClone
.FindFirst strWhere
If .NoMatch Then
MsgBox "Not found."
Else
Me.Bookmark = .Bookmark
End If
End With
End If
 
Allen,

I am wondering if you could help understand this a little more. I've tried
using this code you have written for my own database, but when I attempt to
go to a record, I get an error message reading: "Run-time error '438': Object
doesn't support this property or method" Then if I click 'debug' I'm taken
the the script and this line is highlighted: " strWhere = "[DocumentID] = " &
Me.Goto "

Why am I getting this error message? Is it because my field 'DocumentID' is
an AutoNumber?

And if so, is there another way this script is written when using AutoNumber
fields?

Thanks for any help.

-justin
--
I've never used Access before. HELP!


Allen Browne said:
Place an unbound text box (or combo if there aren't too many records) on
your form (e.g. in the Form Header section).

Name it "Goto".

Set its AfterUpdate property to
[Event Procedure]

Click the Build button (...) beside this.
Access opens the code window.
Paste the following in between the "Private Sub..." and "End Sub" lines:

Dim strWhere As String
If Me.Dirty Then 'Save before move.
Me.Dirty = False
End If
If Not IsNull(Me.Goto) Then
strWhere = "[NameOfYourIDFieldHere] = " & Me.Goto
With Me.RecordsetClone
.FindFirst strWhere
If .NoMatch Then
MsgBox "Not found."
Else
Me.Bookmark = .Bookmark
End If
End With
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

GeorgeH said:
I use an autonumber to identify records. Is there a way to use that field
to
quickly search for records, much like you can enter the record number in
Access's build-in navigation tools to quickly jump to a desired record.
 
Back
Top