custom navigation button in a form (1 Viewer)

Fileandreos

New member
Local time
Today, 05:48
Joined
Feb 21, 2009
Messages
2
Hi all,

I want to add a button to jump to a specific record in my form (frm_Sites). The button reads a parameter from a tekst field to know which record to go to. So far so good if I use the following code (DoCmd.GoToRecord acDataForm, "frm_Sites", acGoTo, txt_Find_Site_Id.Text).

The code above, navigates to the record based on the parameter from the inputbox 'txt_Find_Site_Id.Text'.

What I realy want is to navigate to a specific record, based on a field in the form, not the record count of MS Access. I want to navigate based on a 'Site_Id' value which is one of the fields in the form itself ...

In a SQL query it should look like (select * from tbl_Sites where Site_Id = txt_Find_Site_Id.Text).

I hope I have described my question clear enough for you guys to understand :eek:)

Thanks in advance and hope to have a possible solution soon!

Best Regards,
Fileandreos
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:48
Joined
Feb 19, 2002
Messages
43,550
You would need to use the Find or Seek method. Also, don't use the .text property of a control since that property is ONLY available when the control has the focus. Use the .value property or omit the property altogether since the .value property is the default. Access VBA is different in its usage of these properties from VB.
 

Fileandreos

New member
Local time
Today, 05:48
Joined
Feb 21, 2009
Messages
2
Hi,

For your info I have posted my code to give you a better idea of what I want to try.

(I have used 'value' instead of 'text' which was clearly a better approach. Thanks for the tip!)

I have search on google and looked for the 'seek' and 'find' method but I don't get it ... :(

Regards,
Fileandreos



Private Sub btn_Find_Site_Id_Click()
On Error GoTo Err_btn_Find_Site_Id_Click

Screen.PreviousControl.SetFocus
DoCmd.GoToRecord acDataForm, "frm_Sites", acGoTo, txt_Find_Site_Id.Value
Exit_btn_Find_Site_Id_Click:
Exit Sub
Err_btn_Find_Site_Id_Click:
MsgBox Err.Description
Resume Exit_btn_Find_Site_Id_Click

End Sub
 

Users who are viewing this thread

Top Bottom