Button on From prefill field on different form (1 Viewer)

Andreww1986

New member
Local time
Yesterday, 20:56
Joined
Apr 19, 2020
Messages
19
I have a database that is tracking incidents that occur by application. I have two forms one that holds all the applications information named Application Library and another form labled Incident library.

I have a button on the application form that when clicked will open the Incident form to insert information relating to the "new" incident that may have occurred. I want to have this button also prefill the application name that is referenced on the application form automatically on the incident library form. I am unsure how to tie the button to open the new form as well as prefill the application name.

Any help would be appreciated.

Thanks a bunch!
Andrew
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:56
Joined
Oct 29, 2018
Messages
21,485
Hi Andrew. Welcome to AWF! One approach is to use the OpenArgs argument of the OpenForm method to pass the information. Another is to simply refer to the other form, as long as it stays open, using the Forms!FormName.ControlName syntax. A third is my favorite, using a form/subform setup.
 

Andreww1986

New member
Local time
Yesterday, 20:56
Joined
Apr 19, 2020
Messages
19
Hi Andrew. Welcome to AWF! One approach is to use the OpenArgs argument of the OpenForm method to pass the information. Another is to simply refer to the other form, as long as it stays open, using the Forms!FormName.ControlName syntax. A third is my favorite, using a form/subform setup.

Thanks theDBguy,

I guess my confusion is on how I would finish the code. Currently what I have in place to open the form on button click is below.

Private Sub Command58_Click ( )
DoCmd. OpenForm "Incident Library"
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:56
Joined
Oct 29, 2018
Messages
21,485
Thanks theDBguy,

I guess my confusion is on how I would finish the code. Currently what I have in place to open the form on button click is below.

Private Sub Command58_Click ( )
DoCmd. OpenForm "Incident Library"
End Sub
Hi. That's probably a typo, because there shouldn't be a space before OpenForm.

So, option 1 is to use the OpenArgs argument. For example,

DiCmd.OpenForm "Incident Library", OpenArgs:=Me.ApplicationID

You would then use it in the other form, like:

Me.ApplicationID=Me.OpenArgs

Hope that helps...
 

Andreww1986

New member
Local time
Yesterday, 20:56
Joined
Apr 19, 2020
Messages
19
Hi. That's probably a typo, because there shouldn't be a space before OpenForm.

So, option 1 is to use the OpenArgs argument. For example,

DiCmd.OpenForm "Incident Library", OpenArgs:=Me.ApplicationID

You would then use it in the other form, like:

Me.ApplicationID=Me.OpenArgs

Hope that helps...

Sorry if these are newbie questions.

When you say you would then use it in the other form, like:

Me.ApplicationID=Me.OpenArgs

Where would I insert this code?

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:56
Joined
Oct 29, 2018
Messages
21,485
Sorry if these are newbie questions.

When you say you would then use it in the other form, like:

Me.ApplicationID=Me.OpenArgs

Where would I insert this code?

Thanks
You could use the form's Open or Load event.
 

Andreww1986

New member
Local time
Yesterday, 20:56
Joined
Apr 19, 2020
Messages
19
Ok,

To recap

I have a onclick event of the below:
Private Sub Command58_Click ()
DiCmd.OpenForm"IncidentLibrary", OpenArgs:=Me.Application
End Sub

Would the red text above refer to the field name I am using in my table for the application field on my form) My field name in both tables for Application and Incident Library are Application.

Then I have on the on load event for the Incident Library form

Private Sub Form_Load()
Me.Application=Me.OpenArgs
End Sub

Thanks!
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:56
Joined
Oct 29, 2018
Messages
21,485
Ok,

To recap

I have a onclick event of the below:
Private Sub Command58_Click ()
DiCmd.OpenForm"IncidentLibrary", OpenArgs:=Me.Application
End Sub

Would the red text above refer to the field name I am using in my table for the application field on my form) My field name in both tables for Application and Incident Library are Application.

Then I have on the on load event for the Incident Library form

Private Sub Form_Load()
Me.Application=Me.OpenArgs
End Sub

Thanks!
Hi. Looks good from here. What happened when you tried it?
 

Andreww1986

New member
Local time
Yesterday, 20:56
Joined
Apr 19, 2020
Messages
19
Hi. Looks good from here. What happened when you tried it?

I changed both tables fields from application to system and updated the code.

When I click the button I receive a Compile Error: Method or Data member not found.
 

Micron

AWF VIP
Local time
Yesterday, 20:56
Joined
Oct 20, 2018
Messages
3,478
You went from one reserved word to another? Probably not your problem but just saying...
Put a break on the form open event so that it stops executing. Then in the immediate window of the vb editor, enter
?Me.OpenArgs then hit Return and see what you get. If it just drops the cursor and shows nothing in the window, the argument is Null (or an empty string).
If it returns a value, it is the value of the OpenArgs property. Is it what you expect if you're trying to use it?
and updated the code.
Best that you update us too.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:56
Joined
Oct 29, 2018
Messages
21,485
I changed both tables fields from application to system and updated the code.

When I click the button I receive a Compile Error: Method or Data member not found.
Hi. Did you get an error when it was still "Application" (before you changed it)?
 

Andreww1986

New member
Local time
Yesterday, 20:56
Joined
Apr 19, 2020
Messages
19
Hi. Did you get an error when it was still "Application" (before you changed it)?
Yes I received a Run-time Error "424": Object required. When I went to debug the command line Dicmd.OpenForm"Incident Library", OpenArgs:=Me.Application is highlighted yellow.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:56
Joined
Oct 29, 2018
Messages
21,485
Yes I received a Run-time Error "424": Object required. When I went to debug the command line Dicmd.OpenForm"Incident Library", OpenArgs:=Me.Application is highlighted yellow.
Well, if that's exactly what you used, then you misspelled DoCmd and you didn't have a space after OpenForm, before "Incident Library." Is that really what you used?
 

Andreww1986

New member
Local time
Yesterday, 20:56
Joined
Apr 19, 2020
Messages
19
My mistake code is now corrected to DoCMD with the appropriate spacing now i receive a run time error 2498 an expression you entered is the wrong data type for one of the arguments.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:56
Joined
Oct 29, 2018
Messages
21,485
My mistake code is now corrected to DoCMD with the appropriate spacing now i receive a run time error 2498 an expression you entered is the wrong data type for one of the arguments.
Hi. So, let's back up a bit. Assuming the error is still on the same line, what happens if you try the following code?

MsgBox Me.Application
DoCmd.OpenForm "Incident Library"
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:56
Joined
Oct 29, 2018
Messages
21,485
My mistake code is now corrected to DoCMD with the appropriate spacing now i receive a run time error 2498 an expression you entered is the wrong data type for one of the arguments.
Hi. I was curious, so I gave it a try. Using "Application" as a name doesn't work. I suggest you change it to ApplicationName.
 

Andreww1986

New member
Local time
Yesterday, 20:56
Joined
Apr 19, 2020
Messages
19
I gave your suggestion a try and renamed the table fields to ApplicationName and changed the MsgBox code. I am now receiving a compile error method or data member not found.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:56
Joined
Oct 29, 2018
Messages
21,485
I gave your suggestion a try and renamed the table fields to ApplicationName and changed the MsgBox code. I am now receiving a compile error method or data member not found.
You also need to change the name of the textbox to match.
 

Andreww1986

New member
Local time
Yesterday, 20:56
Joined
Apr 19, 2020
Messages
19
Textbox has been changed when I updated the table. still same error.
 

Users who are viewing this thread

Top Bottom