473,394 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Query open, If Or And condition not working

114 100+
Have a couple of conditions going on that I can't seem to get working correctly.

Have 1 Form only with 3 text boxes that are used in a query, when a command button is clicked using 'Event Procedure'. The VBA Sub that runs (code below) checks to see if 1 or more text boxes had something entered, and if OK the list box row source should be poplulated with a query results. Only need 1 or more of the 3 boxes filled in. For some reason it wants all 3 filled in. Not sure why this is not working the way I want!

If Me.WhatLastName.Value = "" Or IsNull(Me.WhatLastName) And _
Me.WhatFirstName.Value = "" Or IsNull(Me.WhatFirstName) And _
Me.WhatMedRecNo.Value = "" Or IsNull(Me.WhatMedRecNo) Then

MsgBox ("Please enter 1 or more Search values")
GoTo Exit_SearchQuery_Click
Else
Me.SelectPrintItems.RowSource = "Lukup_Query"
Me.SelectPrintItems.Requery

End If

Also when this Form is opened for the 1st time the list box is populated with the complete table. Row Source type = Table/Query, Row Source = Lukup_Query. List box should not populate untill after the button has been clicked and the If test passes with no error.

Should I change the Row Source to a VBA coded SQL Query, or is there a way to do this with the button and list box properties!
Dec 31 '06 #1
3 2216
NeoPa
32,556 Expert Mod 16PB
You really mean :
Expand|Select|Wrap|Line Numbers
  1. If (Me.WhatLastName.Value = "" Or IsNull(Me.WhatLastName)) And _
  2. (Me.WhatFirstName.Value = "" Or IsNull(Me.WhatFirstName)) And _
  3. (Me.WhatMedRecNo.Value = "" Or IsNull(Me.WhatMedRecNo)) Then ...
This ensures the ORs are processed first and the ANDs only connect the results of those ORs.
In which case you should really code it something like :
Expand|Select|Wrap|Line Numbers
  1. If Nz(Me.WhatLastName,"")="" _
  2. And Nz(Me.WhatFirstName,"")="" _
  3. And Nz(Me.WhatMedRecNo,"")="" Then ...
This shorter version would also work :
Expand|Select|Wrap|Line Numbers
  1. If Nz(Me.WhatLastName,"") & _
  2.    Nz(Me.WhatFirstName,"") & _
  3.    Nz(Me.WhatMedRecNo,"")="" Then ...
Dec 31 '06 #2
ljungers
114 100+
Works, Thank You.

Have any idea why the list box is loading 1st thing when the form is opened? Is that because the list box is tied to a Query and if so should I remove that query reference and place the SQL query in my VBA code under the _Click code?
Dec 31 '06 #3
NeoPa
32,556 Expert Mod 16PB
Probably because you have the Row Source property set to the query in the design of the form itself.
You haven't given any indication of when your code runs so it's hard to guess what you're expecting to happen.
What do you want to happen exactly?
Dec 31 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Dave | last post by:
Hi all, I've been trying to figure this out for the last day and a half and it has me stumped. I've got a web application that I wrote that keeps track of trading cards I own, and I'm moving it...
6
by: Ljoha | last post by:
I need to create report where will be shown total quantity of all rows for every hour in some data range. I have a table where I have column in DATETIME format. I have problem to create sql...
5
by: Todd | last post by:
Data related to the query I'm working on is structured such that TableA and TableB are 1-many(optional). If an item on TableA has children on TableB, I need to use the Max(tstamp) from Table B in...
1
by: Chasing Gates | last post by:
I have created a database that brings in a new table weekly. I then made a separate query for each sales rep and a separate report for each rep. (The reports are all identical but call different...
15
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
2
by: Julio Allegue | last post by:
I am getting the wrong Count(*) on vb.net using the ExecuteScalar . It returns all the rows. It doesn't seem to look at the WHERE clause. At the same time, I am getting the correct count on "SQL...
0
by: Chuck36963 | last post by:
Hi all, I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in...
1
by: Intrepid_Yellow | last post by:
Hi, I have the following code that runs my report generator. The user selects a table from a combo box, then whatever fields they want from a list box. (This part all works and the report runs...
2
by: sara | last post by:
I am helping a non-profit track their elder clients and care given to the clients. The organization would like a report that shows various info on ALL clients, such as: # in each town, # and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.