473,804 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA code for displaying MsgBoxs in a parameter query

66 New Member
Hello everyone:

This question is neither urgent nor important, but I post it just in case anyone knows (and wants to give a reply, of course XD).
I have little idea of VBA, but I have dared to write a little piece of code. It is as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Comando551_Click()
  2.   Dim qry As String
  3.   qry = "BUSQUEDA PACIENTES"
  4.   DoCmd.OpenQuery qry
  5.   If [BUSQUEDA PACIENTES].[HISTORIA] Is Not Null Then
  6.     MsgBox ("This person is present in the DB")
  7.   Else
  8.     MsgBox ("This person is not present")
  9.   End If
  10. End Sub
The query (qry) is a parameter query, with the Parameter query criteria (for the "ID" field): [Enter ID]. What I want is to display a msgbox telling whether the person is present in the database or not, after having launched a parameter query prompting the user to provide an ID (which is to be checked against the IDs already present in the database).
Nevertheless, when launched, the query do fire but there seems to be a problem with the first If statement line (If [BUSQUEDA PACIENTES].[HISTORIA] Is Not Null Then). What is the problem here?

Best regards!
May 5 '08 #1
3 1618
FishVal
2,653 Recognized Expert Specialist
Hello. limperger.

You will definitely obtain more simple and more reliable code, if you just follow Nico's suggestion and use a custom form instead of Access query parameter dialog.

Kind regards,
Fish
May 5 '08 #2
NeoPa
32,579 Recognized Expert Moderator MVP
While agreeing completely with Nico & Fish, I appreciate there are times when you need to do things in non-standard ways. Also, learning is never misplaced.

You will have two fundamental problems with this approach.
  1. Main problem - Opening a query displays it for the operator. This is not accessible programmaticall y (# records etc). To access this data the query needs to be opened as a recordset (which doesn't display to the operator of course).
  2. Checking for a Null value in SQL uses X Is Null, but in VBA you need to use the IsNull(X) function.
May 5 '08 #3
limperger
66 New Member
Hello!

First and foremost, thank you for your comments. They're much appreciated. As you can see, I have little idea of VBA code. I even forgot about the Isnull function...
Secondly, this web provided (fontstuff.com) is excellent. I recommend it to anyone here.

Best regards
May 6 '08 #4

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

Similar topics

3
16949
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can create a parameter query in a stored procedure, but how do I use the result set of a parameter query in a select query (in the same or another sp)? In short, if a select query contains a result table that is generated as a parameter query, how do I...
2
2362
by: Russ | last post by:
I've got a report that puts dates at the top of columns and the user is prompted to enter a beginning date when the report is opened. That date is put in a textbox in the first column like this: =DateValue() Then the next columns are textboxes that add 7 to the previous column for the date display of the next week like this: =+7
9
1504
by: Steve Jorgensen | last post by:
First, an example - today, I wanted to print out the parameter values in a querydef object at a break point in the code for subsequent manual debugging of the query. In the past, I would have had to either manually write down the values from the watch window, or break the code, write a custom procedure to print the values for me, then run the code to the breakpoint again. By now, though, my library of collection-oriented tools makes such...
4
5733
by: Andy Davis | last post by:
I have developed a number of reports that are based on parameter queries where the user enters criteria such as a date range and a sales rep say. I want to be able to show a graphical picture in the form of a bar chart based on the data within the report. Can I do this as when I have tried to insert a chart on the report it displays an error saying that it doeds not recognise the parameter criteria. Am I right to assume that maybe a chart...
2
2864
by: lex_tiger3 | last post by:
I have a Report that gets data from a combo box that I created in a form. On the form I have a command button that opens a report OnClick and I also have a cancel button created to close the form OnClick if the user decides not to open a report. The error code 2585 appears when I click the cancel button and the report displays a parameter query for the information that wasn't included by the form. I want the cancel button to close the...
2
1590
by: nsymiakakis | last post by:
Hello Everyone, I am almost completed with this database, the only thing left is to graph the results of a query. I built a parameter query that gives me totals for a date range that I enter. This works great. I created a column called "Month", and I am entering the month and year corresponding to the "Date" field. ie. (03/15/06 for the date) (Mar-06) for Month. If I do the Query to show me 1/1/2006 to 12/31/2006, I get the results with Date...
3
1954
by: Hazza | last post by:
Hi, I am using PHP and mysql to create a website. I am fairly new to PHP, and thus am grateful to anyone who helps! Firstly I am running a homepage, that displays additional content if a user has logged in. I set a loggedin session in the log in page, which I have tested and works fine in other scripts. I am displaying news on the homepage (which is stored in a mysql database), and this works fine when the user accesses the homepage...
0
1581
by: cht13er | last post by:
Good day all, I'm a newish VBA coder who was taught from Google Groups - so thanks to you all very much! I have run into a minor problem, I hope you can give me some help ... I'm running office 2003 for this one. In excel I have a program running ... and based on the results of an optionbutton (called "Form2.Radio_AllParameters") I want to change the SQL that runs a query in access. If the button is True, the SQL should read "WHERE...
0
1537
by: sourpo | last post by:
wonder if anyone can help... I have access db with a whole lot of vb code... If i use access 2000 it works perfectly but when using 2003 it doesn't work properly. The db copies outlook mailboxes... I'm not quite sure why it wont work properly, i can copy my own mailbox but trying to copy some elses wont work, if i export the mailboxes directly through outlook then i can copy them... this isn't an outlook related issue... here is the code which...
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10351
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10096
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.