473,654 Members | 3,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Command Button Problem

72 New Member
Hey Everybody,
I have code for a command button. The button is supposed to open a query with a general criteria of: Forms![Form Name]![Control Name]. The [Column Name] field of the query should match the [Control Name] in the Form. If a record does not exist in the query for the specified control name, I want a message box to display stating so. My code is below:

Expand|Select|Wrap|Line Numbers
  1. If ( ) Then ' If record exists, then open the query below.
  2.     DoCmd.OpenQuery "2 - Total Reflux Tests Query", acViewNormal, acReadOnly
  3. Else ' If record does not exist, then show message below.
  4.     MsgBox "No test(s) found for column " & [Column Name] & ".", vbInformation, "Sorry"
  5. End If
What should go in the if statement?

Thanks!
Jun 13 '07 #1
15 2004
mforema
72 New Member
Hey Everybody,
I have code for a command button. The button is supposed to open a query with a general criteria of: Forms![Form Name]![Control Name]. The [Column Name] field of the query should match the [Control Name] in the Form. If a record does not exist in the query for the specified control name, I want a message box to display stating so. My code is below:

Expand|Select|Wrap|Line Numbers
  1. If ( ) Then ' If record exists, then open the query below.
  2.     DoCmd.OpenQuery "2 - Total Reflux Tests Query", acViewNormal, acReadOnly
  3. Else ' If record does not exist, then show message below.
  4.     MsgBox "No test(s) found for column " & [Column Name] & ".", vbInformation, "Sorry"
  5. End If
What should go in the if statement?

Thanks!
I've tried this expression in the If statement:
Expand|Select|Wrap|Line Numbers
  1. [2 - Total Reflux Tests]![Column Name] = Forms![GeneralColumnSummary - view]![Column Name]
But an error message popped up when I tried to run it:
"Run-time error '2465':
Microsoft Office Access can't find the field '|' referred to in your expression."

What can I do to fix it?
Thanks!
Jun 13 '07 #2
mforema
72 New Member
I've tried this expression in the If statement:
Expand|Select|Wrap|Line Numbers
  1. [2 - Total Reflux Tests]![Column Name] = Forms![GeneralColumnSummary - view]![Column Name]
But an error message popped up when I tried to run it:
"Run-time error '2465':
Microsoft Office Access can't find the field '|' referred to in your expression."

What can I do to fix it?
Thanks!
Can someone please help me???
Jun 14 '07 #3
NeoPa
32,568 Recognized Expert Moderator MVP
Please do not *BUMP* your thread before at least 24 hours have passed.
Our experts and members offer their time voluntarily and do not deserve to be treated with impatience by those who may benefit from their efforts.

MODERATOR.

I will look to answer this later but, like all the other experts, I don't appreciate your impatience. Having received a PM from you too, I'm not feeling too generous towards you at the moment. I'll look at this when I get home from work.
Jun 14 '07 #4
mforema
72 New Member
Please do not *BUMP* your thread before at least 24 hours have passed.
Our experts and members offer their time voluntarily and do not deserve to be treated with impatience by those who may benefit from their efforts.

MODERATOR.

I will look to answer this later but, like all the other experts, I don't appreciate your impatience. Having received a PM from you too, I'm not feeling too generous towards you at the moment. I'll look at this when I get home from work.

To NeoPa and all other Moderators:

I am terribly sorry for coming accross as impatient. I am new to writing on Forums (I didn't even know what "BUMP" means), and thus I had no clue that what I was doing was considered impatient. I also did not know that sending you personal messages requesting help was frowned upon. So, to prevent anymore mistakes and annoyances, I will resign myself from this forum. I'm sorry for upsetting all of you. I really, truly am sorry.

~mforema
Jun 14 '07 #5
JKing
1,206 Recognized Expert Top Contributor
Adding this might work.
The logic behind this is to open the query and search for the first record that matches your control. If there is an existing record with the specified criteria Nomatch will return false. So, in theory this should provide you with the correct logic for your If statement.

Dim db as Database
Dim rstQuery As RecordSet

Set db = CurrentDb
Set rstQuery = db.OpenRecordSe t ("qryName", dpOpenDynaset)

rstQuery.FindFi rst ("[Column Name] = [Forms]![Form]![Control Name]")

If rstQuery.NoMatc h = False Then
*the rest of your code here*

Hope this was helpful.
Jking
Jun 14 '07 #6
mforema
72 New Member
Adding this might work.
The logic behind this is to open the query and search for the first record that matches your control. If there is an existing record with the specified criteria Nomatch will return false. So, in theory this should provide you with the correct logic for your If statement.

Dim db as Database
Dim rstQuery As RecordSet

Set db = CurrentDb
Set rstQuery = db.OpenRecordSe t ("qryName", dpOpenDynaset)

rstQuery.FindFi rst ("[Column Name] = [Forms]![Form]![Control Name]")

If rstQuery.NoMatc h = False Then
*the rest of your code here*

Hope this was helpful.
Jking
Thanks JKing

I tried your code, but the an error message popped up saying "Too few parameters, expected:1." I don't know what that means. When trying to debug, the "Set rstQuery" line was highlighted. Here is my code so far:

Expand|Select|Wrap|Line Numbers
  1. Dim db As Database
  2. Dim rstQuery As Recordset
  3.  
  4. Set db = CurrentDb
  5. Set rstQuery = db.OpenRecordset("2 - Total Reflux Tests Query", dbOpenDynaset)
  6.  
  7. rstQuery.FindFirst ("[Column Name] = [Forms]![GeneralColumnSummary - view]![Control Name]")
  8.  
  9. If (rstQuery.NoMatch = False) Then
  10.     DoCmd.OpenQuery "2 - Total Reflux Tests Query", acViewNormal, acReadOnly
  11. Else
  12.     MsgBox "No tests found for column " & [Column Name] & ".", vbInformation, "Sorry"
  13. End If
Do you see what I did wrong?
Thanks again.
Jun 14 '07 #7
NeoPa
32,568 Recognized Expert Moderator MVP
To NeoPa and all other Moderators:

I am terribly sorry for coming accross as impatient. I am new to writing on Forums (I didn't even know what "BUMP" means), and thus I had no clue that what I was doing was considered impatient. I also did not know that sending you personal messages requesting help was frowned upon. So, to prevent anymore mistakes and annoyances, I will resign myself from this forum. I'm sorry for upsetting all of you. I really, truly am sorry.

~mforema
We're really not all that thin-skinned, don't worry.
Simply, we have to deal with very large numbers of people of all sorts here, so replying in a way that is right for everyone is just not possible. I wanted to impart to you the understanding (which seems to have got across quite adequately) that such things are frowned on (and why). In my reply PM I posted a link so that you can better understand what we're dealing with here, and how members should be using this free resource that is TSDN.

I have no wish for you to leave the forums - that is not what we're all about.
Please enjoy the rest of your stay here.
Jun 14 '07 #8
NeoPa
32,568 Recognized Expert Moderator MVP
Thanks JKing

I tried your code, but the an error message popped up saying "Too few parameters, expected:1." I don't know what that means. When trying to debug, the "Set rstQuery" line was highlighted. Here is my code so far:

Expand|Select|Wrap|Line Numbers
  1. Dim db As Database
  2. Dim rstQuery As Recordset
  3.  
  4. Set db = CurrentDb
  5. Set rstQuery = db.OpenRecordset("2 - Total Reflux Tests Query", dbOpenDynaset)
  6.  
  7. rstQuery.FindFirst ("[Column Name] = [Forms]![GeneralColumnSummary - view]![Control Name]")
  8.  
  9. If (rstQuery.NoMatch = False) Then
  10.     DoCmd.OpenQuery "2 - Total Reflux Tests Query", acViewNormal, acReadOnly
  11. Else
  12.     MsgBox "No tests found for column " & [Column Name] & ".", vbInformation, "Sorry"
  13. End If
Do you see what I did wrong?
Thanks again.
I've checked the line in question and I can't see what your problem could be.
Have you copied /pasted this code in. Sometimes it is very important that you do (Always do so as a general rule).
Is the query name absolutely accurate, and does the query run when opened from the database window?
Can you post the SQL of the query for us to look at please.
Jun 14 '07 #9
NeoPa
32,568 Recognized Expert Moderator MVP
I've tried this expression in the If statement:
Expand|Select|Wrap|Line Numbers
  1. [2 - Total Reflux Tests]![Column Name] = Forms![GeneralColumnSummary - view]![Column Name]
But an error message popped up when I tried to run it:
"Run-time error '2465':
Microsoft Office Access can't find the field '|' referred to in your expression."

What can I do to fix it?
Thanks!
Going back to your earlier post, can you explain in simple English what the two sides of the = test refer to.
Again, nothing jumps out as to why the compiler would think there were an '|' in the equation anywhere.

PS. Lots of traffic since your last post. Best if you review all of it in sequence.
Jun 14 '07 #10

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

Similar topics

2
4003
by: mksql | last post by:
New to Tkinter. Initially, I had some code that was executing button commands at creation, rather than waiting for user action. Some research here gave me a solution, but I am not sure why the extra step is necessary. This causes the "graph" function to execute when the button is created: Button(root, text='OK', command=graph(canvas))) However, this waits until the button is pressed (the desired behavior): def doit(): graph(canvas)
2
3240
by: Paul A. Wilson | last post by:
I'm new to Tkinter programming and am having trouble creating a reusable button bar... I want to be able to feed my class a dictionary of button names and function names, which the class will make. My button bar is implemented a Frame subclass, which takes the button dictionary as an argument and displays the buttons on the screen: class OptionsBar(Frame): def __init__(self, buttonDict, parent=None) Frame.__init__(self, parent)
8
2166
by: bearophileHUGS | last post by:
Hello, I have four things to ask or to suggest, sorry if they seem basic or already discussed. ------------------- I am still ignorant about Tkinter. This little program, after pressing the "Go" eats more and more RAM, is it normal? Can it be avoided? (In normal programs this is isn't a real problem). ! import Tkinter
2
9284
by: Chris Bolus | last post by:
I'm a teacher using MS Access on an RMConnect 2.4 network. On some workstations both I and my students sometimes get an error message when attempting to insert a command button on a form which reads "Invalid use of null". The remainder of the options in the Command Button Wizard are then unavailable and the button wil not work. The only solution is to log on to a different workstation. Any ideas?
6
59257
by: deko | last post by:
I have a several forms that accept user input in a textbox and then take some action based on that input after a command button is clicked. Is it possible issue the command when the user presses Enter rather than clicking the command button? I've tried this, but for some reason it's not working: Private Sub txtFind_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Call cmdFind_Click End Sub
6
1379
by: Mark R | last post by:
Hi Guru's, I have a frontend application where my boss wants to when people are using the database. I have a form which OnOpen, inserts the username, network login and date/time it was opened to a table. I have created a 'Close' button which when clicked, updates the 'Logged_out' time and then quits the application. My problem is that when users click on the cross (top right corner) to close the database, this time is not logged. Is...
8
4309
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender, System.EventArgs e)
14
4960
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons for things like delete, save, edit, cancel buttons - in the footer, or on the form detail section? 2. If in the footer, how do you add them to the tab order?
4
4792
by: John Smith | last post by:
I have a continuous form. there is a command button with the following code for the OnClick event: DoCmd.OpenForm "frmPlants", , , "PlantsID =" & Me!PlantsID I click the button and frmPlants opens up with the record that corresponds to the one on the cont. form. I put that same code for the OnClick of an image control (i.e. the user clicks a little icon to open the form instead of a button) and frmPlants
16
2714
by: Steve | last post by:
I am working on a database that has a main menu, many sub-menus and some sub-sub-menus. They are all forms that have numerous command buttons on them to open forms and reports in the database. The database has hundreds of forms and reports. I was asked to go through all the menu forms and determine if all the buttons worked, if there were any problems when either the form or report opened and to come up with a list of the forms and reports...
0
8285
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
8814
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...
0
8706
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
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
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.