473,763 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Command Button problem - Access 2003

11 New Member
I created two Command buttons in a form, one to preview the entire report and one to "cancel" or exit the form. They both work. I'm trying to create a third Command button to select/filter data from the report. My code to filter the data is:

Private Sub SelectedContrac t_Click()
On Error GoTo Err_SelectedCon tract_Click

strFilter = "[LeaseMasterCont ractId] = '" & Me![LeaseMasterCont ractId] & "'"
DoCmd.OpenRepor t "OPTIMIZEIT-Audit1", acViewPreview, , strFilter

Exit_SelectedCo ntract_Click:
Exit Sub

Err_SelectedCon tract_Click:
MsgBox Err.Description
Resume Exit_SelectedCo ntract_Click

End Sub

I get the error message "Cannot find the field 'LeaseMasterCon tractId' referred to in your expression." I know the field name and report name are correct. I'm not very knowledgeable about VBA so I appreciate any help you can provide.

Krazy
Mar 27 '08 #1
3 2311
Dököll
2,364 Recognized Expert Top Contributor
I created two Command buttons in a form, one to preview the entire report and one to "cancel" or exit the form. They both work. I'm trying to create a third Command button to select/filter data from the report. My code to filter the data is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub SelectedContract_Click()
  2. On Error GoTo Err_SelectedContract_Click
  3.  
  4. strFilter = "[LeaseMasterContractId] = '" & Me![LeaseMasterContractId] & "'"
  5. DoCmd.OpenReport "OPTIMIZEIT-Audit1", acViewPreview, , strFilter
  6.  
  7. Exit_SelectedContract_Click:
  8.     Exit Sub
  9.  
  10. Err_SelectedContract_Click:
  11.     MsgBox Err.Description
  12.     Resume Exit_SelectedContract_Click
  13.  
  14. End Sub
  15.  
  16.  
I get the error message "Cannot find the field 'LeaseMasterCon tractId' referred to in your expression." I know the field name and report name are correct. I'm not very knowledgeable about VBA so I appreciate any help you can provide.

Krazy
Greetings, KrazyKasper!

Have you tried having your wizard create certain buttons for you?

Here is what I have working to exit my database:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub QuitMeNow_Click()
  3. On Error GoTo Err_QuitMeNow_Click
  4.  
  5.  
  6.     DoCmd.Quit
  7.  
  8. Exit_QuitMeNow_Click:
  9.     Exit Sub
  10.  
  11. Err_QuitMeNow_Click:
  12.     MsgBox Err.Description
  13.     Resume Exit_QuitMeNow_Click
  14.  
  15. End Sub
  16.  
  17.  
Nothing fancy just add code under your button named QuitMeNow
Here is what I ahve to pull up my reports, same deal created through wizard:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'Opens Open Report
  3. Private Sub OpenOpenReport_Click() ' this is your button
  4. On Error GoTo ErrHandler
  5.   DoCmd.OpenReport "OpenMeReport", acPreview, acEdit
  6. ErrHandler:
  7.    Exit Sub
  8. End Sub
  9.  
  10.  
I actually have a bit of code with the report using the On No Data procedure pane that'll allow report to not load when empty, thus get to your report in design view and add the additional info so it works well with the code above:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Option Compare Database
  3.  
  4.  
  5. Private Sub Report_NoData(Cancel As Integer)
  6. On Error GoTo ErrHandler
  7. ErrHandler:
  8. MsgBox "Sorry! There are no records to display for this report." & vbCrLf & vbCrLf & _
  9.                "Please be sure data available in the system to continue...", vbInformation + vbOKOnly, _
  10.                "Data Central Report Error"
  11.    Cancel = True
  12.    Exit Sub
  13. End Sub
  14.  
Hope this helps you:-)

In a bit!

Dököll
Mar 28 '08 #2
Fiddler2
19 New Member
I created two Command buttons in a form, one to preview the entire report and one to "cancel" or exit the form. They both work. I'm trying to create a third Command button to select/filter data from the report. My code to filter the data is:

Private Sub SelectedContrac t_Click()
On Error GoTo Err_SelectedCon tract_Click

strFilter = "[LeaseMasterCont ractId] = '" & Me![LeaseMasterCont ractId] & "'"
DoCmd.OpenRepor t "OPTIMIZEIT-Audit1", acViewPreview, , strFilter

Exit_SelectedCo ntract_Click:
Exit Sub

Err_SelectedCon tract_Click:
MsgBox Err.Description
Resume Exit_SelectedCo ntract_Click

End Sub

I get the error message "Cannot find the field 'LeaseMasterCon tractId' referred to in your expression." I know the field name and report name are correct. I'm not very knowledgeable about VBA so I appreciate any help you can provide.

Krazy
The field name must be in the dataset behind the form and on the form itself to be "seen" in your code. Is it there? Also, perhaps an easier way to pull this off is to parameterize your report query and reference the field on your form. To open the report, you'll only need the line you have to open the report as the filter will be "built in" to the query behind the report.
Mar 28 '08 #3
KrazyKasper
11 New Member
Got it done.
Thanks for your help.

Krazy (Bill) Kasper
Jun 9 '08 #4

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

Similar topics

2
7611
by: Sam | last post by:
Trying to change the visible property on a command button (access97) based on a record felid on the form. The felid is a check box felid and I am trying to make the button disappear with the check box s checked. The commend button name is command36 and the check bx feild is named . I have written the following code: IIf Me! = True, Me!Command36.Visible = -1, Me!Command36.Visible
2
9289
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?
5
3222
by: randyelliott | last post by:
Good Day, I have a MS Access (Access 2000 now upgraded to 2003) database that tracks customer information. One function of this database is to create an encrypted license file for our software, which is then emailed out to the customer. The encryption string is based on information in the database and can only be generated by executing a DOS command. This is done from within the database by clicking a button on a form that triggers a...
14
4972
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?
0
1850
by: M G Henry | last post by:
I am using Access 2003 and have a form with two subforms on them. I would like to be able to use a command button to add the row of data ( 5 fields ) that are completed on the subform, as well as refresh the parent form which has a list box that shows the values from the first field ( custname ) that have been added thus far to the table linked to the subform. My form has two subforms and I would like the command buttons to work...
24
15749
Dököll
by: Dököll | last post by:
Jumped for joy last night after learning, indeed, the command button wizard can be switched on or off. Well this occured here, with my Access 2000...an attempt to redo at work failed. Here's the scenario, quite amusing, and I'll try to sum this up quickly:-) At home, when the command button wizard (Access 2000) loads and give me some wonderful options/selection tips, the result, code is pre-written for the button when completed. I...
2
3914
by: Hothead | last post by:
Hi, I’m having difficulty getting a report in ms access 2003 to print (physically print to printer) once I’ve clicked a command button in a form. What’s the best way to do this? I tried connecting to a printout macro however I’ve not installed the correct wizard. I’m 6,000 miles away from my home office so installing it is more difficult than it sounds. Is there a simple way to do this using a simple sql statement? Thanks in...
3
3994
by: getro | last post by:
Hi Everyone, I need to open an Access 2003 form to a specific record from a custom Outlook 2003 Appointment form. The form has a command button that would pass a record id to access and open the appropriate record. I have searched through many Outlook and Access books and the web and cannot seem to find any info on this. Your help would be greatly appreciated. Serge
5
12349
by: Ken OHanlon | last post by:
I wrote a short program that uses "SendObject". It works fine on my computer, it works fine on my clients computer, but when I copy/paste it up to the server to use it there also, Access issues the following message: The expression on click......The command or Action "SendObject" isn't available now. If you click on the See Details button you get: Visual Basic for Applications (VBA) encountered a problem while attempting to access a...
2
2922
beacon
by: beacon | last post by:
Hi everybody, I've searched and searched for the answers to these questions until I've turned blue in the face, so I finally decided to come here for some assistance. Here's the info I'm working with: MS Access 2003 Call log database using data access pages One table called tblCRS_Data_Log Primary key is CallNo An assortment of other fields, including check, text, and combo boxes
0
9563
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
10145
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
9998
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...
0
8822
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
7366
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
6642
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
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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
3
3523
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.