Open form using WhereCondition and OpenArgs

tihmir

Registered User.
Local time
Yesterday, 23:08
Joined
May 1, 2018
Messages
257
Hi all,
I am tring with a cobobox (afterupdate) when I make selection to open another form "fm_Inspection" with where condition and I need to apply OpenArgs to subform "fm_PSD" on the opened form with this code:
Code:
    If Me.Dirty = True Then
        Me.Dirty = False
    End If
    
    If Me.Type = "KP" Then
        DoCmd.OpenForm "fm_Inspection", , , [Inspection ID]=" & Me.Inspection, , , Me!fm_PSD.Form!Code
        Exit Sub
    End If
On Load on the subform "fm_PSD" a have Me.Code= OpenArgs.
However, I miss something and the code doesn't work
 
saying 'doesn't work' doesn't help - provide the error description

As it is it looks like your error will be a syntax error, you are missing a double quote - chances are the error message will give you a clue where
 
That OpenArgs goes to the form being opened, fm_Inspection ?

I would have thought the syntax would be Me.Code = Me.Parent.OpenArgs?

Also you pass a value, not state a control in a destination form.?
 
it doesn't make sense to me.

..., , , Me!fm_PSD.Form!Code

this means the subform frm_PSD is already open and you are passing its "code" to frm_Inspection.
then on your statement:

"On Load on the subform "fm_PSD" a have Me.Code= OpenArgs" ?
 
it doesn't make sense to me.

..., , , Me!fm_PSD.Form!Code

this means the subform frm_PSD is already open and you are passing its "code" to frm_Inspection.
then on your statement:

"On Load on the subform "fm_PSD" a have Me.Code= OpenArgs" ?
No, I just think the o/p is confused on how OpenArgs work?
 
hi, gasman, my reply is for the op.
well if that the case, from frm_Inspection Load Event, pass the OpenArgs to the subform:
remember the subform, get initiazed first.

private sub form_load()
me!subformName.Form!Code = Me.OpenArgs
end sub
 
The form "Inspection" has a subform tab control page "fm_PSD" with control "Code". I need this control name be filled with my selection from combobox in 1st form "Type" - If Me.Type = "KP" Then
Is that possible?
 
repeat - what is the error? - because your openform line clearly has an error.
 
are you going to "Add new record" on subform "frm_PSD", then assign the OpenArgs to "Code" textbox?
on form frm_Inspection Load Event:



Code:
private sub form_load()
' check if a parameter was passed
if trim(me.openargs & "") <> "" then
    Forms!frm_Inspection!frm_psd.SetFocus
    Forms!frm_Inspection!frm_psd.Form!Code.SetFocus
    DoCmd.GoToRecord , , acNewRec
    
    'assign Openargs to code
    me!frm_psd.form!code = me.openargs
end if
end sub
 
Last edited:
repeat - what is the error? - because your openform line clearly has an error.
The error is 2465 - MS Access can not find the the field "fm_PSD" referred to in your expression.

are you going to "Add new record" on subform "frm_PSD", then assign the OpenArgs to "Code" textbox?
Yes, arnelgp, I am trying to add new record to the sub form

DoCmd.OpenForm "fm_Inspection", , , [Inspection ID]=" & Me.Inspection, , , Me!fm_PSD.Form!Code
This part of the code highlights in yellow
 
Last edited:
The error is 2465 - MS Access can not find the the field "fm_PSD" referred to in your expression.


Yes, arnelgp, I am trying to add new record to the sub form


This part of the code highlights in yellow
So unless you have a control called frm_PSD (which I really doubt you have?) on the form where this code is?, you pass the value that you want Code on frm_PSD to have.
This can be a control value on the form where you are using the code.?

Then do as Arnel suggests.

I think you are throughly confused on how OpenARgs is meant to work.?

https://docs.microsoft.com/en-us/office/vba/api/access.form.openargs

HTH
 

Users who are viewing this thread

Back
Top Bottom