Link to home
Start Free TrialLog in
Avatar of drtopserv
drtopservFlag for Israel

asked on

Type mismatch access vba

Hi,
Well i wanna open a form in access 2010 with parameter from controls in other form .

in "on click even" in a control in a main form i have this code :

DoCmd.OpenForm "frmShowAllBigClientsOrders", acNormal, , "[Date = #" & Format(Me.cboBigClientsOrdersDate, "mm/dd/yyyy") & "#" And "ExportBankBigClientsStatus = " & Me.cboExportBankBigClientsStatus, acFormReadOnly, acWindowNormal
I got an error :
type mismatch
how can i fix it ?
Avatar of Norie
Norie

There should be a ] after Date.
Avatar of drtopserv

ASKER

sorry yea sure it is there, still have type mismatched
i just mis-typed here not in the real code in the form
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark 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
@drtopserv,

One of the ways I use to debug this type of error is that I generally define the criteria string outside the OpenForm method.  This allows me to add a debug.print statement before the OpenForm method.

Dim strCriteria as string

strCriteria = "[Date] = #" & Format(Me.cboBigClientsOrdersDate, "mm/dd/yyyy") & "#"  _
                   & " And [ExportBankBigClientsStatus] = " & Me.cboExportBankBigClientsStatus
debug.print strCriteria
DoCmd.OpenForm "frmShowAllBigClientsOrders", acNormal, , strCriteria, acFormReadOnly, acWindowNormal

When I'm developing, I will generally put a breakpoint on the OpenForm line and examine the output of the print command in the immediate window before I execute the OpenForm.  This way, I can make edits to the criteria string, and move the focus back to that line to get it right before opening the new form.
You need to check for valid field values. Are the fields blank perhaps? Empty date might give that kind of error.
@Gustav Brock
your code works!!
how did u change in it?
and what is the \/ thing in date is for?
The backslash is the escape character that forces the following character, the slash, to be read literally. Otherwise, the slash would be read as the date separator which isn't always a slash but can be a hyphen - even a space.
This way the date expression will always be, say, 2015/10/11 which never will fail neither in SQL nor ADO.

/gustav
works as a charm