Solved

Trying to open a form with one of two form criteria

Posted on 2011-09-07
10
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36497257
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
ID: 36497264
Assuming both are numeric ...

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

mx
0
 

Author Comment

by:SteveL13
ID: 36497298
I'm getting a runtime error 3075 with both suggestions.  Both are numeric.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 36497318

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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36497326
SteveL13,
in what event did you place the codes

post the codes that you are USING
0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 36497331
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
ID: 36497377
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 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 36497425
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
ID: 36498014
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
ID: 36502557
These two lines worked:

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

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

Thank you very much!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

728 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