Tbo value according to button clicked (1 Viewer)

ToucHDowN

Registered User.
Local time
Today, 05:18
Joined
May 4, 2014
Messages
36
Hi,

I have a form, with just two buttons, say "Tyre" and "Engine". These buttons open the same form, say frmCar.

What I want to do is when I click the "Tyre" button, a tbo in the frmCar to get as value "Tyre" and when I click the "Engine" button, the same tbo in the frmCar to get the value "Engine".

Could you help me with the code?

Thanks.
 

JHB

Have been here a while
Local time
Today, 13:18
Joined
Jun 17, 2012
Messages
7,732
Use the open arguments.
 

ToucHDowN

Registered User.
Local time
Today, 05:18
Joined
May 4, 2014
Messages
36
Use the open arguments.

This is where I came up so far....:

Code:
Private Sub Tyre_Click()

DoCmd.OpenForm "frmCars"
    
End Sub

What I don't know is how to syntax the following expression:

When frmCars opens, find tboDetail and assign to it the value "Tyre"

Thanks.
 

ToucHDowN

Registered User.
Local time
Today, 05:18
Joined
May 4, 2014
Messages
36
This is where I came up so far....:

Code:
Private Sub Tyre_Click()

DoCmd.OpenForm "frmCars"
    
End Sub

What I don't know is how to syntax the following expression:

When frmCars opens, find tboDetail and assign to it the value "Tyre"

Thanks.

Ok, the code is:

Forms!frmCar!tboDetail = "Tyre"

Thanks.
 

bob fitz

AWF VIP
Local time
Today, 12:18
Joined
May 23, 2011
Messages
4,717
The OP has asked me to take a look at this thread and advice if I can.

I think the advice given by JHB in post #2 is sound. The correct syntax for the Tyre button would be:
Code:
Private Sub Tyre_Click()
  DoCmd.OpenForm "frmCars",,,,,"Tyre"
End Sub
The correct syntax for the Engine button would probably be:
Code:
Private Sub Engine_Click()
  DoCmd.OpenForm "frmCars",,,,,"Engine"
End Sub
You then need to put some code in the On Open event of frmCars which would examine its own OpenArgs property. If the value is not null then assign the OpenArgs value to a control on the form.

Just wondering what exactly you want to do once frmCars has opened though.
Are you intending to enter a new record or edit an existing record.
 

ToucHDowN

Registered User.
Local time
Today, 05:18
Joined
May 4, 2014
Messages
36
The OP has asked me to take a look at this thread and advice if I can.

I think the advice given by JHB in post #2 is sound. The correct syntax for the Tyre button would be:
Code:
Private Sub Tyre_Click()
  DoCmd.OpenForm "frmCars",,,,,"Tyre"
End Sub
The correct syntax for the Engine button would probably be:
Code:
Private Sub Engine_Click()
  DoCmd.OpenForm "frmCars",,,,,"Engine"
End Sub
You then need to put some code in the On Open event of frmCars which would examine its own OpenArgs property. If the value is not null then assign the OpenArgs value to a control on the form.

Just wondering what exactly you want to do once frmCars has opened though.
Are you intending to enter a new record or edit an existing record.

Hi Bob,

Thanks for stopping by,

In frmCars there is tbo1, which is unbound. In tbo1 I want a value to get assigned according to which button was previously pressed (in another form) in order to open frmCars.

My goal is, then, to have another tbo in frmCars, say tbo2, to check: if tbo1="Tyre" then Me.tbo2.ControlSource = a field from a query.

Respectively, if tbo1="Engine" (meaning, if "Engine" button was pressed to get to frmCars), then tbo2 should get a value from another field of the query that is the source of the frmCars.

This way, I guess, I won't need to have 2 separate forms, one to load Tyre details and one to load Engine details, according to which button was pressed.

Hope it's clear. Just to say that the tbo1 button in frmCars is unbound. I don't want to lookup for "tyre" value. I want to assign this value, or "Engine" value, to tbo1, according to which button was pressed.

You saved me once Bob, hope this will be the second and the last one!

Thanks!
 

bob fitz

AWF VIP
Local time
Today, 12:18
Joined
May 23, 2011
Messages
4,717
I mean, one more textbox, say tbo2.
Of course, I should have realized that tbo would be your abbreviation for "text box".:eek:
My goal is, then, to have another tbo in frmCars, say tbo2, to check: if tbo1="Tyre" then Me.tbo2.ControlSource = a field from a query.
I don't think you need these text boxes if they are just used to determine which field should be used as the Control Source of a text box. You could just examine the "OpenArgs" property in the forms On Open event as I mentioned earlier and change the Control Source property of a tbo then.
 

ToucHDowN

Registered User.
Local time
Today, 05:18
Joined
May 4, 2014
Messages
36
Of course, I should have realized that tbo would be your abbreviation for "text box".:eek: I don't think you need these text boxes if they are just used to determine which field should be used as the Control Source of a text box. You could just examine the "OpenArgs" property in the forms On Open event as I mentioned earlier and change the Control Source property of a tbo then.

Ok Bob, I'll give it a try and will report back.

Thanks.
 

Users who are viewing this thread

Top Bottom