docmd.openform - this is driving me crazy

Gand114

Registered User.
Local time
Today, 16:02
Joined
Apr 21, 2016
Messages
15
Hi dears,
I am about to throw the pc from the window, so hopefully someone will have pity of the this newbe of mine...

The following in a standard VBA routine doesn't work
I get a run-time 2465

Code:
Private Sub Comando2_Click()

DoCmd.OpenReport "newreport", acViewPreview, , "[QQ_Retrieve nolo export]![ragione sociale]= '" & Forms(Opnenewreportex).Controls(CasellaCombinata0) & "'"


End Sub

if I copy paste exactly the same in the immediate window


Code:
DoCmd.OpenReport "newreport", acViewPreview, , "[QQ_Retrieve nolo export]![ragione sociale]= '" & Forms(Opnenewreportex).Controls(CasellaCombinata0) & "'"

It works exactly as it suppose to..

Why? Cannot figure it out at all...

Thanks to anyone who will help!
 
Try removing the [QQ_Retrieve nolo export]! from you criteria field, and replace it with just the field name. The ! changes the reference
 
Hi Minty,
thanks a lot for your prompt reply!
If i got it right i tried changing it as follows:

Code:
Private Sub Comando2_Click()

DoCmd.OpenReport "newreport", acViewPreview, , "[ragione sociale]= '" & Forms(Opnenewreportex).Controls(CasellaCombinata0) & "'"


End Sub

Still exatcly the very same erro :banghead: while of course it works in the immediate window (why htere it works makes no sense to me)

I wanna shoot the laptop in the outer space...
 
Is Comando2 On the same form as Forms(Opnenewreportex).Controls(CasellaCombinata0) ?
Is CasellaCombinata0 a number or text value?
 
Hi Minty,

yep, Comando2 is on the same form as Forms(Opnenewreportex).Controls(CasellaCombinata0)

CasellaCombinata0 is a text

Thanks!

Ciao
 
In that case try;
Code:
Private Sub Comando2_Click()

DoCmd.OpenReport "newreport", acViewPreview, , "[ragione sociale]= '" & me.CasellaCombinata0 & "'"


End Sub
 
Thanks Minty!
That worked (not clear to me why it worked, but stil....)

Thanks a lot!
 
Using the forms! type reference whilst you are already on that form will cause an error.
Me.YourControlName will always refer to the current form instance you are on.
 

Users who are viewing this thread

Back
Top Bottom