Solved

Access 2010 runtime popup / form

Posted on 2012-03-28
4
819 Views
Last Modified: 2012-03-31
Hi
I am using access 2010.

I am using a form to view / edit a table.  At runtime,  when the user clicks on a button, I would like to create a popup / form with a bound combobox.  The user would select a value in the combobox and then that value would be returned to the main form.

The name of the combobox would be                                            cmboName
This combobox would be bound to                                                 [Table Merchants].[Names]
Value would be returned to the main form in the variable        UserResponse

This is a formidable challenge for me.  I would appreciate any help that I can get.
0
Comment
Question by:peispud
  • 2
4 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 37775890
Instead of using a variable for the return value, create a hidden unbound  textbox on the primary form for the user response.


Then in the AfterUpdate event of the combo box on your popup form:

Forms!MyMainFormName.txtMyHiddenTextBox = Me.cmboName
Then once the popup is closed, you can refer to the hidden textbox at any time with code on the primary form:

Me.txtMyHiddenTextBox
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 37776150
Another approach to accomplishing this is to open the popup form using the acDialog windowmode argument of the Openform method.  

    docmd.OpenForm "frmPopup", , , , ,acDialog

This pause all further processing of the code in the module that opens the form.  Then, instead of closing the popup, set it's visible property to False.  This will allow the remainder of the code in the calling module to continue, allowing you to pull the value from the popup form into your variable.  It would looks something like:

Private Sub yourbuttonname_Click

    docmd.OpenForm "frmPopup", , , , ,acDialog
    if currentproject.Allforms("frmPopup").isloaded = false then Exit Sub

    UserResponse = forms!frmPopup.cmboName
    docmd.close acform, "frmPopUp"

End Sub

This is a little longer than the process mentioned by mbizup, but has the benefit that it allows you to use this popup form for more than one main form, if you need to.  Whenever I use a popup like this, I generally have Cancel and Continue buttons on that form, if the user selects Cancel, I close the form. This causes the code above to exit the sub on the line after the OpenForm method, because the popup is no longer loaded.  If the user clicks Continue, I check to make sure a value has been entered in the combo, and if so, I hide the popup form (me.visible = false), which allows the rest of the code in the original button event to continue processing.

HTH
Dale
0
 

Author Closing Comment

by:peispud
ID: 37791405
Thank you.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 37791408
Glad to help.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question