Solved Set default value to main forms ID (1 Viewer)

tmyers

Well-known member
Local time
Today, 10:52
Joined
Sep 8, 2020
Messages
1,090
On a form that is opened from my main form, is there a way to set the default value for a field to equal that of the main form?
I typically use the following:
[Forms]![JobQuote]![JobID]

JobID is what keeps everything under a certain job within my application. What I am trying to do, is when the second form is opened (via a button on the main form that opens the form to records with the matching JobID), is set the default value of the JobID field to equal to the value of the JobID from the main form. This is so if the user enters additional data, it will automatically assign it the relevant JobID. The data within the form is populated via data imported from excel that is assigned all of its relevant ID's during the import process, so any data added in by the user after the fact needs the JobID added to it.

Using the syntax above does not do anything and just throws a #NAME error within the field.

How can I set the default value for my JobID to equal the JobID from the main form?
 

Minty

AWF VIP
Local time
Today, 15:52
Joined
Jul 26, 2013
Messages
10,371
Pass the ID in the openargs property of the open form command.

On the Form load event use something like

Me.YourControlname.DefaultValue = "= " & Me.Openargs
 

tmyers

Well-known member
Local time
Today, 10:52
Joined
Sep 8, 2020
Messages
1,090
I just added that to my on load event, and the field still says "0" when entering new data.

I used:
Me.JobID.DefaultValue = " = " & Me.OpenArgs

Did I mess that up?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:52
Joined
Oct 29, 2018
Messages
21,468
Hi. Another approach is to convert your second form into a form/subform setup.
 

tmyers

Well-known member
Local time
Today, 10:52
Joined
Sep 8, 2020
Messages
1,090
I would love to make it into a sub form, but the amount of data I need to show makes it a very large form. I opted to make it its own form because of this. Making it a sub form would make this easier, as I could just set the master/child properties.
 

tmyers

Well-known member
Local time
Today, 10:52
Joined
Sep 8, 2020
Messages
1,090
Rewording my google search took me to:
I was able to modify the answer there and it is now working how I wanted.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:52
Joined
Oct 29, 2018
Messages
21,468
I would love to make it into a sub form, but the amount of data I need to show makes it a very large form. I opted to make it its own form because of this. Making it a sub form would make this easier, as I could just set the master/child properties.
Hi. I think you misunderstood what I said. I wasn't saying to add the second form to your main form as a subform. Rather, I'm saying change the setup of your second form so that it is a subform to an almost empty main form with nothing but the JobID in it. You don't even have to display anything on the main form.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:52
Joined
Oct 29, 2018
Messages
21,468
Rewording my google search took me to:
I was able to modify the answer there and it is now working how I wanted.
Hi. Glad to hear you found a working solution. Good luck with your project.
 

Minty

AWF VIP
Local time
Today, 15:52
Joined
Jul 26, 2013
Messages
10,371
I just added that to my on load event, and the field still says "0" when entering new data.

I used:
Me.JobID.DefaultValue = " = " & Me.OpenArgs

Did I mess that up?
Add a debug.print Me.OpenArgs to make sure the passed value is actually arriving at your form.

You may not need the " = " & if your value is a number though
 
Last edited:

tmyers

Well-known member
Local time
Today, 10:52
Joined
Sep 8, 2020
Messages
1,090
Hi. I think you misunderstood what I said. I wasn't saying to add the second form to your main form as a subform. Rather, I'm saying change the setup of your second form so that it is a subform to an almost empty main form with nothing but the JobID in it. You don't even have to display anything on the main form.
I did misunderstand what you said.
That is pretty clever though. I will probably end up using that in the future!
 

Users who are viewing this thread

Top Bottom