Send variables from modal to main form

grahamvb

Registered User.
Local time
Today, 14:28
Joined
Aug 27, 2013
Messages
57
Hello Access Programmers,

I have a form that has a button that opens a modal form on top allowing the user to perform a task, when done the modal form closes, returning the user to the underlying form to continue their work.

That modal form creates some information that I would like to transmit to the underlying form.

In this thread, http://www.access-programmers.co.uk/forums/showthread.php?t=198302 bob suggests a public function on the main form called by a line on the modal form. Here is what I created to accomplish this.

Main Form
Code:
Public Sub SetCombos(varEID As Variant, varCID As Variant)
 
    Debug.Print "varEID: " & varEID
    Debug.Print "varCID: " & varCID
 
End Sub

Modal (popup) Form
Code:
Private Sub btnSave_Click()
 
    DoCmd.RunCommand acCmdSaveRecord
 
[COLOR=green]' call public procedure on main form[/COLOR]
    varEID = Me.EID
    varCID = Me.CID
    [COLOR=red]Forms!frmMain.SetCombos(varEID, varCID)[/COLOR] [COLOR=green]' Access will not accept this line[/COLOR]
[COLOR=green]                                          ' (Compile error: Expected: =)[/COLOR]
 
    DoCmd.Close acForm, "frmPopup", acSaveNo
 
End Sub
Access does not like the red line. Where am I going wrong?
Thanks for looking at this.
 
Try with no parenthesis.

Forms!frmMain.SetCombos varEID, varCID
 
Actually, public Subs are fine.

Chris.
 
Yep, their fine.

Public Subs could not be called directly from the property sheet (well they could but they would be called more than once) so they had to be Functions for that. (I think that was fixed after XP/Access2003).

But Subs are okay for the use they are being used for here.

Chris.
 
Thank you TJPoorman.

This works flawlessly passing variables from the modal form to the main form.

Main Form:
Code:
Public Sub SetCombos(varEID As Variant, varCID As Variant)
 
    Debug.Print "varEID: " & varEID
    Debug.Print "varCID: " & varCID
 
End Sub

Modal Form:
Code:
Private Sub btnSave_Click()
 
    DoCmd.RunCommand acCmdSaveRecord
 
' call public procedure on main form
    varEID = Me.EID
    varCID = Me.CID
    Forms!frmMain.SetCombos varEID, varCID
 
    DoCmd.Close acForm, "frmPopup", acSaveNo
 
End Sub

Thanks to all of you who looked at this.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom