Question Go to record based on value in textbox. (1 Viewer)

behedwin

New member
Local time
Yesterday, 20:48
Joined
Nov 15, 2017
Messages
9
I want a textbox where i can type in a ID number.
When i type in the number, i want to go to that record on my form.


I have looked at GoToRecord.
But i dont understand how to get it to work....



How should the code look like?


Go to record based on value in textbox.
 

June7

AWF VIP
Local time
Yesterday, 19:48
Joined
Mar 9, 2014
Messages
5,470
GoToRecord would need a record number - this is the sequence number from the current dataset of the form, not the primary key ID.

Try using FindRecord command instead.
 

behedwin

New member
Local time
Yesterday, 20:48
Joined
Nov 15, 2017
Messages
9
GoToRecord would need a record number - this is the sequence number from the current dataset of the form, not the primary key ID.

Try using FindRecord command instead.

Ok, ill google on findrecord. Any idea how the code would look like?
 

behedwin

New member
Local time
Yesterday, 20:48
Joined
Nov 15, 2017
Messages
9
ok, im a bit new to this vba so just googling around makes my head hurt.


If textbox value is 4 then go to record with ID 4....
how do i do that with either findfirst or findrecord?
 

Gasman

Enthusiastic Amateur
Local time
Today, 04:48
Joined
Sep 21, 2011
Messages
14,260
Here is something I use to go back to the record I was on after a requery.
I am saving the autonumber key and then using that to locate the record again.

FWIW the MS example shows exactly how to use it as well.?

Code:
Private Sub cmdRequery_Click()
    Dim lngId As Long
    Dim strCriteria As String
    
    ' Save record so requery on subform will pick up all last record written
    If Me.Dirty Then Me.Dirty = False
    lngId = Me.ID
    Me.Requery
    strCriteria = "ID=" & lngId
    ' Go back to record we were on
    Me.Recordset.FindFirst strCriteria

End Sub

HTH
 

behedwin

New member
Local time
Yesterday, 20:48
Joined
Nov 15, 2017
Messages
9
Yes, that worked.


Using it on the "on current" event and when i change record or go to a new record... everything seems to update accordingly.



thanks.
 

Users who are viewing this thread

Top Bottom