Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global Variables

Status
Not open for further replies.

bhujanga

Programmer
Oct 18, 2007
181
US
Actually I have two questions. The first is how to get a variable to stay alive long enough to use it in another Sub. For example, if I set a variable in some code and then that code opens a popup form, then I click a button on the popup, and that code needs to be able to reference the variable assigned in the code that opened the popup.

The other question, which in this case would eliminate the need for the global variable, is: why doesn't the rest of the code run after the popup is closed. For example: I have these records that reference photos that appear on the form. If the user clicks a button they can delete the photo from the list so it no longer appears. When they do this, I want ask them if they also want to delete the file itself or not - so I open the popup that has two buttons on it - one for deleting the file file and one for just removing it from the list. So if they click on the 'Dlete File" button that code deletes the file. Then I want the rest of the original code to run, which deletes the record, but it never goes back. Is it possible to get it to resume? Below is the code I have now. The commands after the OpenForm command never get executed.

Sub cmdDeleteRecord_Click()
strPopUp = "PopUpDeleteFile"
DoCmd.OpenForm strPopUp

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End Sub
 
You should find this useful:

If you wish to make code execution pause until the user selects an item on the pop-up, you you have to set the Window Mode to Dialog as a form open argument.

The wizard code you show is deprecated by Microsoft! You may wish to look at DoCmd.RunCommand.
 
Thanks for the information. I'm still having a little difficulty though. The acDialog for the WindowMode does allow the code to continue, only now I can't get it to wait until I'm done with the popup - it just keeps going. Is there a way to pause it until the popup closes?
 
Here is the outline of an example.

Code:
Sub TestDialog()
DoCmd.OpenForm "frmYesNo", , , , , acDialog
If Forms!frmYesNo.txtAnswer = "Yes" Then
    Debug.Print "Ok"
    DoCmd.Close acForm, "frmYesNo"
Else
    Debug.Print "Ok"
    DoCmd.Close acForm, "frmYesNo"
End If
End Sub

On frmYesNo
Code:
Private Sub cmdYes_Click()
Me.txtAnswer = "Yes"
Me.Visible = False
End Sub

The dialog will only halt execution if the form is visible. It will not halt if you step through code.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top