Solved Set default value to main forms ID

tmyers

Well-known member
Local time
Today, 08:40
Joined
Sep 8, 2020
Messages
1,091
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?
 
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
 
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?
 
Hi. Another approach is to convert your second form into a form/subform setup.
 
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.
 
Rewording my google search took me to:
I was able to modify the answer there and it is now working how I wanted.
 
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.
 
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.
 
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:
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

Back
Top Bottom