Solved

Trying to open a form with one of two form criteria

Posted on 2011-09-07
10
182 Views
Last Modified: 2012-05-12
I have a form which contains two combo boxes.  When the user makes an entry in one of the other of the combo boxes I want the second form to open.  This syntax is not working.  I get an "Runtime error 13.  Type mismatch" error.

DoCmd.OpenForm "frmIncidentDataNEW", , , "[RecN]=" & Me.cboSelectRecord & "" Or "[JobN]=" & Me.cboJobN & ""

Can someone spot the error for me?

--Steve
0
Comment
Question by:SteveL13
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
use this

if both are Number Data TYpe

DoCmd.OpenForm "frmIncidentDataNEW", , , "[RecN]=" & Me.cboSelectRecord & " Or [JobN]=" & Me.cboJobN

if both are Text Data TYpe

DoCmd.OpenForm "frmIncidentDataNEW", , , "[RecN]='" & Me.cboSelectRecord & "' Or [JobN]='" & Me.cboJobN & "'"


if that is not the case, post which field is NUMBER and which is TEXT


0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Assuming both are numeric ...

DoCmd.OpenForm "frmIncidentDataNEW", , , "[RecN]=" & Me.cboSelectRecord & " Or [JobN]= " & Me.cboJobN

mx
0
 

Author Comment

by:SteveL13
Comment Utility
I'm getting a runtime error 3075 with both suggestions.  Both are numeric.
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility

it will be better to use a command button to open the form, doing a test which combo box is not Null

private sub btnOpen_click()

if Me.cboSelectRecord & ""<>""  And Me.cboJobN & ""="" then
  DoCmd.OpenForm "frmIncidentDataNEW", , , "[RecN]=" & Me.cboSelectRecord

' or this one
  DoCmd.OpenForm "frmIncidentDataNEW", , , "[RecN]='" & Me.cboSelectRecord & "'"
end if

if Me.cboSelectRecord & ""=""  And Me.cboJobN & ""<>"" then
  DoCmd.OpenForm "frmIncidentDataNEW", , , "[JobN]= " & Me.cboJobN

' or this one
  DoCmd.OpenForm "frmIncidentDataNEW", , , "[JobN]= '" & Me.cboJobN & "'"
end if

End sub


0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
SteveL13,
in what event did you place the codes

post the codes that you are USING
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
Where are you running this code, a command button?

Could you run it in the AfterUpdate event of each combo box?  If so, then just set the Where condition for the appropriate combo box.

If not, you might want to try using the NZ function, like:

DoCmd.OpenForm "frmIncidentDataNEW", , , "[RecN]=" & NZ(Me.cboSelectRecord,0) & " Or [JobN]= " & NZ(Me.cboJobN, 0)

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
I don't follow the "Or" logic in the where condition.

The "Where" argument should only really need to specify *one* criteria...

I mean you could need to filter the form on two fileds, but this should be rare.

Even so, I would probaly be an AND, not an OR

"RecID=" & me.recID & " AND EmpID=" & me.EmpID

So can you first explain to us how you are trying to open this form?
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
BTW,  when you post an error #, please post the description that goes with it.  Most of us don't have the entire MS error code system memorized.

;-)
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
If you copied and pasted the string...it is squirlly with typos given that both combos values are numeric
"[RecN]=" & Me.cboSelectRecord & "" Or "[JobN]=" & Me.cboJobN & ""
Spacing and mega-quotes are evil.  Chr(34) is your friend
MsgBox'ing a bad string and seeing the quotes that are embedded (or not supposed to be) helps
It'll also help sort out whether the combo boxes are indeed returning what you expect (numeric values)

try

Dim myFilter as string
myfilter = "[RecN]=" & Me.cboSelectRecord & " Or [JobN]=" & Me.cboJobN
msgbox myFilter
DoCmd.OpenForm "frmIncidentDataNEW", , , myfilter


The message box will tell you right away if you're not inputting what you expected
0
 

Author Closing Comment

by:SteveL13
Comment Utility
These two lines worked:

  DoCmd.OpenForm "frmIncidentDataNEW", , , "[RecN]=" & Me.cboSelectRecord

  DoCmd.OpenForm "frmIncidentDataNEW", , , "[JobN]= " & Me.cboJobN

Thank you very much!
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now