Passing data from a form back to the module that called it

J_Orrell

Registered User.
Local time
Today, 17:01
Joined
May 17, 2004
Messages
55
Hi guys,

Sorry it was difficult to know if I should post this to forms or modules.

I have a VBA module which imports data from a CSV file into an import-buffer table. When the data has been imported into the buffer table, the code uses docmd.openform to open a form which shows all the data in the buffer.

I want to put two button-controls on the form, "Import" and "Cancel", both of which close the forum and return back to the module which opened the form, but I want the "Import" button to somehow send a True value (or similar) back. This would signify that the user has chosen to complete the import process and not cancel it. And after that, depending on whether they pressed Cancel or Import, I'll use code to move the data from the import buffer to another table.

How do I get a form to pass a value back to the module when it closes?

Thanks
 
Define a global Boolean variable in your module e.g.
Global blnImport as Boolean

Add this line to the Import button code
BlnImport=True

Then in your module code add
If blnImport= True Then
'your import code goes here
BlnImport=False 'reset variable
End If
 
Last edited:
Good grief why didn't I think of that. Haven't tried it yet but obviously it will work. Sometimes you just need someone else to point out the bleedin' obvious to you! :banghead:

Thanks
 
And open the form as a dialog

DoCmd.OpenForm "mydialog", acNormal, , , , acDialog, Me.Name
MsgBox "You selected " & Me.Tag

mydialog
Code:
Private Sub Command0_Click()
    Retrn "yes"
End Sub

Private Sub Command1_Click()
    Retrn "no"
End Sub

Private Sub Retrn(v As String)
    Forms(OpenArgs).Tag = v
    DoCmd.Close
End Sub
 

Users who are viewing this thread

Back
Top Bottom