Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click event to open a specific record

Status
Not open for further replies.

croiva25

Technical User
Dec 3, 2003
125
AU
Hello guys,

This is the code that I use to double click on text box displaying certain data that calls the function that will go to a particular form/screen and open it displaying data relevant for that record

Private Sub Text40_DblClick(Cancel As Integer)

Dim ctl As Control
Dim frm As Form

Set frm = Forms!frmSearch
Set ctl = frm!Text40

Call OpenEdit_ARegisterEntry(ctl.Text)

End Sub

But in stead of doing this I have a command button and would like to do the same thing by clicking on the button,it opens the relevant form with relevant data,but when I do that this is the error message I get and highlights the line of code

error: object doesn't support this property or method
Call OpenEdit_ARegisterEntry(ctl.Text)

which property do I need to assign to my control(that being a command button) in order for this to work, anybody.

Thanks heaps

 
Is ctl still referencing a TextBox ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hello PHV, Yes I know it is still referencing a textbox, but my question was, what do I need to put in so it is referencing a COMMAND BUTTON, I know the error but not how to fix it.

Because I put this same code under the command button click or double click event and it is the property that I am not assigning properly, that gets highlighted.

Hope you can help

Thanks
 
I have done this in my database - what i did is search for a customer by name and then when i clicked the name field it opened the customer form and jumped straight to the customer record... This can be used with a command button too:
Here is the code i used - note the "customerID" is my Primary Key Field, the "Search_for_Customer" form is the source form and the "customer_form" is the target form.

DoCmd.OpenForm "customer_form", acNormal, "", "", , acNormal
DoCmd.Maximize
DoCmd.GoToControl "CustomerID"
DoCmd.FindRecord Forms!Search_For_Customer!CustomerID, acEntire, False, , False, acCurrent, True

One thing you need to make sure is that you are looking for the same field in both forms - here its "CustomerID" - This would not work if the FindRecord command was Forms!Search_For_Customer!CustomerName - as this is text.

Hope this helps
Regards
'Viper
 
Hi!

The .Text property of a control is only available when the control has focus (and only for some controls, combos and textboxes, at least, but not command buttons, they might have for instance .Caption). When using a command button for this code, the control doesn't have focus, so to refer to the value contained in the control, use the .Value property:

[tt]Call OpenEdit_ARegisterEntry(ctl.Value)[/tt]

- or pass the whole control to the sub, where you can address the different properties within.

[tt]Public Sub OpenEdit_ARegisterEntry(ctl as control)[/tt]

call it with:
[tt]Call OpenEdit_ARegisterEntry(ctl)[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top