473,386 Members | 1,706 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,386 software developers and data experts.

Command Button Problem

72
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 1983
mforema
72
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
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,556 Expert Mod 16PB
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
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 Expert 1GB
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.OpenRecordSet ("qryName", dpOpenDynaset)

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

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

Hope this was helpful.
Jking
Jun 14 '07 #6
mforema
72
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.OpenRecordSet ("qryName", dpOpenDynaset)

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

If rstQuery.NoMatch = 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,556 Expert Mod 16PB
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,556 Expert Mod 16PB
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,556 Expert Mod 16PB
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
mforema
72
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.

I believe I copied/pasted the code. The name is also accurate, because I always copy and paste it into the code. The query also works everytime I open it from the database. The SQL for the query is as follows:

Expand|Select|Wrap|Line Numbers
  1. SELECT [2 - Total Reflux Tests].Plant, [2 - Total Reflux Tests].Column, [2 - Total Reflux Tests].Date, [2 - Total Reflux Tests].[Test Materials], [2 - Total Reflux Tests].[Time for Test], [2 - Total Reflux Tests].[Steam (pph)], [2 - Total Reflux Tests].[dP (mm Hg)], [2 - Total Reflux Tests].[TCP (mm Hg)], [2 - Total Reflux Tests].[# Calculated Stages], [2 - Total Reflux Tests].[Calculated HETP], [2 - Total Reflux Tests].[HETP Theoretical], [2 - Total Reflux Tests].[# Theoretical Stages], [2 - Total Reflux Tests].Efficiency
  2. FROM [2 - Total Reflux Tests]
  3. WHERE ((([2 - Total Reflux Tests].Column)=[Forms]![GeneralColumnDetails - view]![Column Name]));
Thanks!
Jun 18 '07 #11
mforema
72
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.

That 'equation' should mean that the [Column Name] in the table is the same as the current [Column Name] on the form. I hope that makes sense. I thought it would work in the IF...Else statement, b/c the 'Reflux Test' table only has data for certain 'Columns'; some 'columns' don't have reflux tests. So, I wanted the code to open the query for the current column on the form ONLY if there existed the reflux test data for that column. If I just open the query, and the current column on the form is not in the reflux table, then the query shows up empty. If the current column on the form is in the reflux table, then the query shows data for it. I hope this clarifies my problem.

Thank you for your help!
Jun 18 '07 #12
NeoPa
32,556 Expert Mod 16PB
Before I go any further I need to repost an equivalent set of SQL for your query but which is legible. This has absolutely no effect on the query itself, just makes working on it a little easier.
Expand|Select|Wrap|Line Numbers
  1. SELECT Plant,
  2.        [Column],
  3.        [Date],
  4.        [Test Materials],
  5.        [Time for Test],
  6.        [Steam (pph)],
  7.        [dP (mm Hg)],
  8.        [TCP (mm Hg)],
  9.        [# Calculated Stages],
  10.        [Calculated HETP],
  11.        [HETP Theoretical],
  12.        [# Theoretical Stages],
  13.        Efficiency
  14. FROM [2 - Total Reflux Tests]
  15. WHERE ([Column]=[Forms]![GeneralColumnDetails - view]![Column Name]);
Jun 19 '07 #13
NeoPa
32,556 Expert Mod 16PB
From this you will see that the column name in the table is actually [Column] rather than [Column Name].
Try changing your code (from post #7) to reflect this.
Jun 19 '07 #14
mforema
72
From this you will see that the column name in the table is actually [Column] rather than [Column Name].
Try changing your code (from post #7) to reflect this.
Yes, very true. I changed it, and I still got an error message stating that Forms![GeneralColumnDetails - view]![Column Name] was not recognized as an acceptable field or expression.

So, I figured that I needed to take it out of the expression...and it worked! If that doesn't make any sense, I'm probably using the wrong jargon. Below is the code that finally worked:

Expand|Select|Wrap|Line Numbers
  1. Dim rstTable As Recordset
  2. Set rstTable = CurrentDb.OpenRecordset("2 - Total Reflux Tests", dbOpenDynaset)
  3.  
  4. rstTable.FindFirst ("Column = '" & Forms![GeneralColumnDetails - view]![Column Name] & "'")
  5.  
  6. If (rstTable.NoMatch = 0) Then
  7.     DoCmd.OpenQuery "2 - Total Reflux Tests Query", acViewNormal, acReadOnly
  8. Else
  9.     MsgBox "No tests found for column " & [Column Name] & ".", vbInformation, "Sorry"
  10. End If
Thanks for your help. Your questions helped me to research the solution more effectively.
Jun 19 '07 #15
NeoPa
32,556 Expert Mod 16PB
I'm pleased that helped you.
I would offer a little advice. Finding names for objects can be quite important when working with them. A long intricate name, which is also very similar to another long intricate name (for a different object) is likely to cause you confusion. Noticing when you're referring to the table and when the query is not too easy in your setup. Clarity helps to avoid confusion errors.
Anyway, good luck with your project :)
Jun 19 '07 #16

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

Similar topics

2
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...
2
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....
8
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...
2
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...
6
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...
6
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...
8
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...
14
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...
4
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...
16
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
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...

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.