Solved

Trying to open a form with one of two form criteria

Posted on 2011-09-07
10
183 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
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
 
LVL 119

Accepted Solution

by:
Rey Obrero 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 119

Expert Comment

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

post the codes that you are USING
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 47

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 47

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

920 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

13 Experts available now in Live!

Get 1:1 Help Now