?
Solved

Trying to open a form with one of two form criteria

Posted on 2011-09-07
10
Medium Priority
?
188 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 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
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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 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