Open a subform as popup

Morgandy

Registered User.
Local time
Today, 12:12
Joined
Nov 29, 2008
Messages
42
Is there a way to open a subform as a popup or a form from a form to the same ID as the current file you were on?

My goal is to have a form that is only for viewing and open the editable user friendly form to edit the information. I don't want to be forced to do a search twice for the same ID.
 
Yes use something like;

Code:
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "FRM_YourForm"
    
    stLinkCriteria = "[LinkID]=" & Me![ControlName] [COLOR="SeaGreen"]'Where ControlName is the name of the control that hold the LinkID on your current form[/COLOR]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Place this behind the on click event of a button or event that you will use to trigger the form opening.
 
I know it would be more work, but I'm just starting to learn VB. Would you be willing to put the parts I'm supposed to edit in italics or something? It would help me read the code.
 
Code:
Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "[I][B]FRM_YourForm[/B][/I]" [COLOR="Lime"]'Where FRM_YourForm is the form you wish to open[/COLOR]
    
    stLinkCriteria = "[[I][B]LinkID[/B][/I]]=" & Me![[I][B]ControlName[/B][/I]] [COLOR="Lime"]'Where LinkID is the linking field and ControlName is the name of the control that holds the LinkID on your current form[/COLOR]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
 
You need a little more code if you intend to add records with the popup form. In the popup form's BeforeInsert Event, you need to populate the foreign key field:

Me.TheKeyField = Forms!theoriginalformname!TheKeyField
 

Users who are viewing this thread

Back
Top Bottom