Inserting temporary variable into a field (2 Viewers)

maxgold

New member
Local time
Today, 01:01
Joined
Jan 28, 2022
Messages
20
Hello,

I just started my first larger ms-access project. I am using a button to open a different Form with data mode set to "Add". When the form is opened, I would like to automatically insert a temporary variable into one of the fields.

A bit more context: I have two forms, one that shows information on a person (based on a person table) and one that shows information on a specific order a specific person has made (based on an order table). I also created a button in the person form that opens the order form to create a new order. I have saved the person's name in a temporary variable. When the order form opens, I would like to automatically insert the person's name into the appropriate field.

So far, I have only worked with Macros, so I have no experience with Modules, although I'm willing to learn!

I would be grateful for any pointers!

Best,
Max
 

June7

AWF VIP
Local time
Yesterday, 15:01
Joined
Mar 9, 2014
Messages
5,466
Order should save the customer ID not a name. Pass the ID to order (OpenArgs is one method). Order form can have the customer table in RecordSource. Bind textboxes to Customer fields but lock them to prevent edit.

Have you considered a form/subform arrangement?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:01
Joined
Oct 29, 2018
Messages
21,454
Hi Max. Welcome to AWF!

How did you create the temporary variable? Is it a global variable?
 

maxgold

New member
Local time
Today, 01:01
Joined
Jan 28, 2022
Messages
20
Hey, thanks for your fast replies!

I already have a subform in the customer form as a preview of the orders, but since there are quite a lot of fields, I would prefer opening a different form for adding and editing orders.

What is the difference between saving customer ID as a temporary variable and using OpenArgs? I used SetTempVar to create my temporary variable.

Do I need to build a new query to add a second record source to the form? I only see a way to change the record source but not how to add a second record source...
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:01
Joined
Oct 29, 2018
Messages
21,454
You could create a macro on your form and use the Set Value action. The only thing you have to decide is which event to use. For starters, you could try using a Command Button to assign the value of the TempVar to the field. Just a thought...
 

maxgold

New member
Local time
Today, 01:01
Joined
Jan 28, 2022
Messages
20
@theDBguy : I tried that but this is not an existing option, and when I try to type in SetValue it doesn't take it and the field is cleared as soon as I click somewhere else...

Do I need to enable this somehow?

1643370676574.png
 

June7

AWF VIP
Local time
Yesterday, 15:01
Joined
Mar 9, 2014
Messages
5,466
TempVar has to be defined, set, referenced. Passing a value with OpenArgs is simpler, especially if it is the only use of the value. I've never used TempVars and Global variable only few times.

Have to click on Show All Actions to make SetValue available.
 

maxgold

New member
Local time
Today, 01:01
Joined
Jan 28, 2022
Messages
20
Thanks to you both, I did not see the big "Show All Actions" Button... It is working now using the temporary variable, but I will also have a look at OpenArgs.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:01
Joined
Oct 29, 2018
Messages
21,454
Thanks to you both, I did not see the big "Show All Actions" Button... It is working now using the temporary variable, but I will also have a look at OpenArgs.
Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom