OpenArgs problem

mort

Registered User.
Local time
Today, 14:58
Joined
Mar 19, 2018
Messages
30
Hi all,

To registrer items I use a main form connected to a subform. These to work perfectly together.

In the subform there is a combobox with 15 different alternatives. In the subform i have a button called "details", and when clicked it launches a new form based on the combo box selection. This works fine as well.

My problem is passing the OpenArgs so the underlying tables between the subform and combo box selections gets connected. The primary ID in the subform is "Beslag_ID".

Can someone please look at my code and tell me whats wrong?

In the subform (calling form) the combo box is called "Beslagtype" and the code for the button click is as follows:

If Me.Beslagtype = "Annet beslag" Then
strform = "frm_reg_annetbeslag"
ElseIf Me.Beslagtype = "Sporprøve åsted" Then
strform = "frm_Reg_sporprøve_åsted"
ElseIf Me.Beslagtype = "Datamaskin" Then
strform = "frm_reg_datamaskin"
ElseIf Me.Beslagtype = "Dokument\Notat" Then
strform = "frm_reg_dokument\notat"
ElseIf Me.Beslagtype = "Gjenstand" Then
strform = "frm_reg_gjenstand"
ElseIf Me.Beslagtype = "Kjøretøy" Then
strform = "frm_reg_kjøretøy"
ElseIf Me.Beslagtype = "Mobiltelefon" Then
strform = "frm_reg_mobiltelefon"
ElseIf Me.Beslagtype = "Narkotika\Legemiddel" Then
strform = "frm_reg_narkotika\legemiddel"
ElseIf Me.Beslagtype = "Nøkler" Then
strform = "frm_reg_nøkler"
ElseIf Me.Beslagtype = "Penger" Then
strform = "frm_reg_penger"
ElseIf Me.Beslagtype = "Simkort" Then
strform = "frm_reg_simkort"
ElseIf Me.Beslagtype = "Våpen" Then
strform = "frm_reg_våpen"
ElseIf Me.Beslagtype = "Bankkonto" Then
strform = "frm_reg_bankkonto"
ElseIf Me.Beslagtype = "Brukerkonto Internett" Then
strform = "frm_reg_brukerkontointernett"
ElseIf Me.Beslagtype = "Video-overvåkning" Then
strform = "frm_reg_videoovervåkning"
End If
DoCmd.OpenForm strform, acNormal, , "Beslag_ID=" & Me.Beslag_ID
End Sub

In the called form (which opens on the click event) my code is this:
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
DoCmd.GoToRecord , , acNewRec
Me.Beslag_ID = Me.OpenArgs
End If
End Sub

This does not work! The value in the field "Beslag_ID" does not automatically pass to the called form. Can someone please help me?
 
Sorry, the code I am using is this:

DoCmd.OpenForm strform, , , , , , "Beslag_ID=" & Me.Beslag_ID

I get the error message: "Run-time error '.2147352567 (800200009)':

The value you have entered is not valid for this field (translation from Norwegian)
 
As you are trying to filter to open the form at a specific record, I think the original placing in the where clause was correct and that open args aren't needed.

Use the original code from post 1 and remove the open args code in form load event
 
Besides the issue you DO have, you have another issue...
Code:
DoCmd.OpenForm strform, , , , , , [COLOR="Red"]"Beslag_ID=" & Me.Beslag_ID[/COLOR]
calls the form.
The form checks
Code:
Private Sub Form_Load()
   [COLOR="red"]If Not IsNull(Me.OpenArgs)[/COLOR] Then
      DoCmd.GoToRecord , , acNewRec
      Me.Beslag_ID = Me.OpenArgs
   End If
End Sub

As you are ALWAYS passing a value, your code would ALWAYS be hit. This may be also causing other issues.

More important, you are setting Me.Beslag_ID = "Beslag_ID=" & Me.Beslag_ID, which may be causing your error. I'd simply pass Me.Beslag_ID in Me.OpenArgs. I'd use if not nz(Me.OpenArgs,0) = 0 then rather than seeing if it is null. This avoids issues where you accidentally pass a value from the parent.
 
Last edited:
It appears you have 15 or so forms that are identical with the exception of the filter. Aside from the fact that it is Not the best way to go about this, no other filterering should be needed.

However, using one subform with the advice given to you by Ridders and Mark would alleviate the need for that long If/ELSEIF statement and increase performance and efficiency.
 
Google the correct placement of openargs of openform.


Private Sub Form_Load()
If Me.OpenArgs & "" <> "" Then
DoCmd.GoToRecord , , acNewRec
Me.Beslag_ID = Me.OpenArgs
End If
End Sub
 
Rename all your form same as names in the cirresponding item in the combo with Prefix "frm_reg_".

Then you dont need the Ifs to test, just open it:

DoCmd.OpenForm "frm_reg_" & me.Beslagtype
 

Users who are viewing this thread

Back
Top Bottom