Carlos Blanco
Carlos Blanco

Reputation: 8762

Openargs when form is already open

Is it possible to change the Openargs values once the form is already open in Access? It works only the first time the form is open. It fails of the form is open already.

EDIT:

I have this code in the onActivate event of the form

If Not IsNull(Me.OpenArgs) Then
    Me.Recordset.FindFirst ("Id =" & Me.OpenArgs)
    If Me.Recordset.NoMatch Then
        MsgBox "ISOS not found"
    End If
End If

Me.OpenArgs contains the result of a search in another form that uses this command DoCmd.OpenForm "<Form_Name>", acNormal, , , , acWindowNormal, Forms!Lookup_Form!Id to open up the main form.

Upvotes: 1

Views: 3031

Answers (2)

Andrew Lockhart
Andrew Lockhart

Reputation: 174

I've had to solve this same problem recently for a project I'm working on, so I thought I'd offer up the solution I came up with.

The easiest thing I found to do in this situation is to call DoCmd.Close right before the DoCmd.OpenForm. This will close the current instance of the form and open a new one, which will force the Form_Load event to fire again with the new arguments.

DoCmd.Close acForm, "Form2", acSaveNo
DoCmd.OpenForm "Form2", acNormal, , , , , {arg1}|{arg2}

The two assumptions here are: 1. That the state of "Form2" is always being initialized by code in the Form_Load event. 2. There is no state data in "Form2" that I'm trying to retain when passing new arguments.

Upvotes: 4

Fionnuala
Fionnuala

Reputation: 91306

How about running your code from the search form, like so:

Dim frm As Form

If Not CurrentProject.AllForms("Form1").IsLoaded Then
    DoCmd.OpenForm "Form1"
End If

Set frm = Forms!Form1
frm.Recordset.FindFirst ("Id =" & Me.ID)
If frm.Recordset.NoMatch Then
    MsgBox "ISOS not found"
End If

Upvotes: 3

Related Questions