How to goto a specific record as requested by the user

  • Thread starter Thread starter jhanby1
  • Start date Start date
J

jhanby1

So I have a text box and a button. I want to be able to enter a Case
Number (not the PK) into the txtGoToCase, click the button, and have
the case info be pulled up onto the current form (which is already
setup to show all the desired fields). How?
 
jhanby,
Instead of a text control, use a combo box that lists all possible PKs.
Set LimitToList = Yes, and that will prevent entry of illegitimate PK's...
less chance for user entry errors.
I use this code on the AfterUpdate event of the combo (ex. cboGoToCase)
(use your own mames)
DoCmd.GoToControl "PKNo"
DoCmd.FindRecord cboGoToCase
I'm assuming that even though PK is not a "key" field... only one record
will be returned...
 
I would rather keep the text box. I'm not using the primary key to
search the records at all. Here is the code I have for the cmdGoToCase
button:

Private Sub cmdGoToCase_Click()

Dim strGoToCase As String

strGoToCase = Forms!frmMainPage2!fsubCaseDetails!txtGoToCase
DoCmd.GoToRecord , , acGoTo, strGoToCase

End Sub

All I need to do is figure out how to allow the strGoToCase value be
equal to the user-defined Case Number. After that, its a question of
getting the GoToRecord method to search the records by the Case Number
instead of the record number.
 
And yes, there are no duplicates of the Case Numbers, so only one
record will be returned.
 
Try using the combo wizard....choose the 3 option ....find a record
based.......
 
Thanks Albert! That worked. I generated the code I needed (utilizing
the recordset object), and I just converted it to a textbox.
 
Back
Top