Link to home
Start Free TrialLog in
Avatar of pdvsa
pdvsaFlag for United States of America

asked on

Open Args

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
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

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
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.
I always pass the value like this:

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

/gustav
Avatar of pdvsa

ASKER

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

"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
Avatar of pdvsa

ASKER

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.
Avatar of COACHMAN99
COACHMAN99

why not save the openargs to a global variable before opening the second form?
maybe I am missing something?
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.
correction(missing "s")

Tempvar!MyID=Me.ID.value
should be
Tempvars!MyID=Me.ID.value
Avatar of pdvsa

ASKER

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

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
Avatar of pdvsa

ASKER

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)
@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?
Avatar of pdvsa

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pdvsa

ASKER

Perfect.  thank you.  I have been wanting to get that code right for quite awhile.  grateful for your help.
Avatar of pdvsa

ASKER

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

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"
Avatar of pdvsa

ASKER

thank you for the response Rey...