Solved

Open Args

Posted on 2016-10-20
19
37 Views
Last Modified: 2016-10-31
I have a form:  frmDraws
I have a button on this frm that takes me to an OPTION form: frmRateOptions
then from this form I choose to open another form.
I think I lose the OpenArgs, correct because I am opening another form?  

How can I temporarily "save" the OpenArgs?  


Private Sub cmdRates_Click()

    DoCmd.OpenForm "frmRatesChoose", , , , , , OpenArgs:=Me.ID
   
End Sub

frmRatesChoose (UNBOUND FORM):
I click the button for the option I want and the form opens with the following ON LOAD:


Private Sub Form_Load()

         If Nz(Me.OpenArgs, "") <> "" Then
       
            Me.Filter = "[DrawID] = " & Me.OpenArgs 'I lose the open args.
            Me.FilterOn = True
                   
        End If

End Sub



Let me know if you need additional information.
thank you fo rthe help
0
Comment
Question by:pdvsa
19 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 41851887
OpenArgs is a property of the form, not a variable, so it will show up in the first form you open (frmRatesChoose), but unless you pass that value to the 2nd form, it will not show up in that form.  However, you should be able to refer to it from the 2nd form with syntax like:

Forms("frmRatesChoose").OpenArgs
0
 
LVL 33

Expert Comment

by:ste5an
ID: 41851888
Well, how does the code in
frmRatesChoose (UNBOUND FORM):
 I click the button for the option I want and the form opens with the following ON LOAD:
looks like?

You need to handover the arguments.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41851955
I always pass the value like this:

    DoCmd.OpenForm "frmRatesChoose", , , , , , Me!ID.Value

/gustav
0
 

Author Comment

by:pdvsa
ID: 41852087
Dale:
frmRatesChoose (btnLibor):
 DoCmd.OpenForm "frmInterest_Libor", , , Forms("frmRatesChoose").OpenArgs
==>use a where condition?  

fyi:
frmInterest_Libor On Load:
Private Sub Form_Load()

         If Nz(Me.OpenArgs, "") <> "" Then
       
            Me.Filter = "[DrawID] = " & Me.OpenArgs 'I lose the open args.
            Me.FilterOn = True
                   
        End If

End Sub

Open in new window

0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 41852256
"frmRatesChoose (UNBOUND FORM):"

if your form is unbound, there is no record source, hence there is no data available when you open/load the form.

- try first setting the record source of your form in design view and save
- then your openargs option in the load event of the form
0
 

Author Comment

by:pdvsa
ID: 41852323
Rey, thank you.  I was more interested in saving the open args for use later.  Setting the record source of the unbound form was my Plan B and I can do that quite easily.  I have a feeling saving the open args will be more difficult walk through than I thought.

I will keep question open a bit longer.
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 41852356
why not save the openargs to a global variable before opening the second form?
maybe I am missing something?
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 41852475
you can use the Tempvars collection to save the openargs

Private Sub cmdRates_Click()

Tempvar!MyID=Me.ID.value

End sub

now you can use the TempVar!ID anywhere in your application
-try it
-unlike the global variable that loses its value when an error occur, tempvars variables don't.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 41852483
correction(missing "s")

Tempvar!MyID=Me.ID.value
should be
Tempvars!MyID=Me.ID.value
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:pdvsa
ID: 41852638
Rey, wouldnt I need to adjust the ON LOAD event on the form if I am using TempVars?

If not mistaken, I think its something like this:
Private Sub Form_Load()

    If Not IsNull(TempVars!myID) Then

        With Me.RecordsetClone
        .FindFirst "[DrawID]=" & TempVars!myID
      If Not .NoMatch Then
            Me.Bookmark = .Bookmark
      End If
        End With

    End If


End Sub

Open in new window

0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 41852730
Yes, you can do that, provided your form is not UNBOUND

1:Private Sub Form_Load()
2:
3:    If TempVars!myID & "" <>"" Then  ' I prefer this syntax
4:
5:        With Me.RecordsetClone
6:        .FindFirst "[DrawID]=" & TempVars!myID
7:      If Not .NoMatch Then
8:            Me.Bookmark = .Bookmark
9:      End If
10:        End With
11:
12:    End If
13:
14:
15:End Sub
0
 

Author Comment

by:pdvsa
ID: 41852737
Rey, do I have the below correct?  

form 1
Private Sub cmdRates_Click()

      ' DoCmd.OpenForm "frmRatesChoose", , , , , , OpenArgs:=Me.ID
        DoCmd.OpenForm "frmRatesChoose", , , , , , TempVars!myID = Me.ID.Value
        
End Sub

Open in new window


form2: (unbound form)
DrawID is the ID to open the frmInterest_Libor to.  
Private Sub cmdLibor_Click()

   On Error GoTo ID_Click_Err

    On Error Resume Next
    If (Form.Dirty) Then
        DoCmd.RunCommand acCmdSaveRecord
    End If
    If (MacroError.Number <> 0) Then
        Beep
        MsgBox MacroError.Description, vbOKOnly, ""
        Exit Sub
    End If
    On Error GoTo 0
    DoCmd.OpenForm "frmInterest_Libor", acNormal, "", "[DrawID]=" & Nz(ID, 0), , acNormal
    If (Not IsNull(ID)) Then
        TempVars.Add "CurrentID", Me.ID.Value     'WHEN CONVERTING FROM A MACRO IT DOESN'T PUT ME.ID.VALUE.  IT'S A LIMITATION OF ACCESS.
    End If
    If (IsNull(ID)) Then
        TempVars.Add "CurrentID", Nz(DMax("[ID]", Form.RecordSource), 0)
    End If
    DoCmd.Requery ""
    DoCmd.SearchForRecord , "", acFirst, "[ID]=" & TempVars!CurrentID
    TempVars.Remove "CurrentID"


ID_Click_Exit:
    Exit Sub

ID_Click_Err:
    MsgBox Error$
    Resume ID_Click_Exit

Open in new window



End Sub

form 3
the ON LOAD event (see question above)
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 41852765
@pdvsa,

what is the name of form1, form2, form3?
which form is UNBOUND?

in plain English, how do you want the operation to proceed? beginning  from form1


your code in form1 (revised)
Private Sub cmdRates_Click()

TempVars!myID = Me.ID.Value

        DoCmd.OpenForm "frmRatesChoose", , , , , , TempVars!myID        
End Sub

-here you are opening the form  "frmRatesChoose"
- after opening form "frmRatesChoose", what do you want to do?

Note: you will NOT find any record in an UNBOUND form-- are we clear on this?
0
 

Author Comment

by:pdvsa
ID: 41852782
Rey,

- after opening form "frmRatesChoose", what do you want to do?
Answer:
I want to open Form 3 (its a bound form) where DrawID = ID (from Form 1).  So I ahve 3 Forms:
1st = frmDraws (Bound, has ID)... cmdRates_Click() - I see your response above so I think I am good on this one
2nd = frmRatesChoose (Unbound) - this is the tricky one...cmdLibor_Click() - see long code above
3rd frmInterest_Libor (Bound, has DrawID, this is the ON LOAD form)

Note: you will NOT find any record in an UNBOUND form-- are we clear on this?
answer:  Yes, I am clear on that.

thank you for the help.
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 41852817
replace your codes with this

your code in form1 (revised)
 Private Sub cmdRates_Click()

 TempVars!myID = Me.ID.Value

         DoCmd.OpenForm "frmRatesChoose"  ' the openArgs is useless here since "frmRatesChoose" is unbound
 End Sub



Private Sub cmdLibor_Click()
'this will open "frmInterest_Libor" on the record DrawID=TempVars!myID (filtered)
DoCmd.OpenForm "frmInterest_Libor", acNormal, "", "[DrawID]=" &  TempVars!myID,, acNormal

end sub

if you want to have all records shown and not filtered, use the openArgs

DoCmd.OpenForm "frmInterest_Libor", openargs:=TempVars!myID

then in the load event of form "frmInterest_Libor", use the FindFirst to find the record


 1:Private Sub Form_Load()
 2:
 3:    If TempVars!myID & "" <>"" Then  ' I prefer this syntax
 4:
 5:        With Me.RecordsetClone
 6:        .FindFirst "[DrawID]=" & TempVars!myID
 7:      If Not .NoMatch Then
 8:            Me.Bookmark = .Bookmark
 9:      End If
 10:        End With
 11:
 12:    End If
 13:
 14:
 15:End Sub
0
 

Author Closing Comment

by:pdvsa
ID: 41852835
Perfect.  thank you.  I have been wanting to get that code right for quite awhile.  grateful for your help.
0
 

Author Comment

by:pdvsa
ID: 41866513
Rey, not sure if you are still monitoring.

Wouldn't I need to clear out the previous TempVars before assigning a new one?  I have added line to remove it but I don't think it is correct? I am having a conflict

Private Sub cmdRates_Click()

   TempVars.Remove "ID"
   TempVars!myID = Forms!frmDRaws.subfrmlDraws_Details1.Form.ID.Value
  
         DoCmd.OpenForm "frmRatesChoose"  ' the openArgs is useless here since "frmRatesChoose" is unbound
        
End Sub

Open in new window

0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 41866701
the value of the tempvars variable is always the last one you assigned to it, so no need for TempVars.Remove "ID"
bit if you want to, it should be  TempVars.Remove "myID"
0
 

Author Comment

by:pdvsa
ID: 41866753
thank you for the response Rey...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now