Solved

Trying to open a form with one of two form criteria

Posted on 2011-09-07
10
184 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 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

823 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