473,779 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MS Access Database Macro

6 New Member
I have a database that has thousands of customer records. Right now I use a macro that prompts the user for the customer registration number and then exports the record to excel. It prompts the user prior to exporting every year. Is there any way to prompt the user once for the registration number then store the value in a variable that is reference in the criteria of the queries so it consecutively exports the records to excel. I want seperate excel sheets so I do not want to use a union query. Thanks.
Dec 6 '07 #1
11 1931
BradHodge
166 Recognized Expert New Member
I have a database that has thousands of customer records. Right now I use a macro that prompts the user for the customer registration number and then exports the record to excel. It prompts the user prior to exporting every year. Is there any way to prompt the user once for the registration number then store the value in a variable that is reference in the criteria of the queries so it consecutively exports the records to excel. I want seperate excel sheets so I do not want to use a union query. Thanks.
Can you expand a little bit on how your macro currently works? How are you getting it to print several different reports with a single year on each?

It should be a relatively simple thing to set up a variable that will hold your registration number (need to know what format the registration number is in (e.g. number, text, etc.)).

Brad.
Dec 6 '07 #2
rccoburn
6 New Member
Can you expand a little bit on how your macro currently works? How are you getting it to print several different reports with a single year on each?

It should be a relatively simple thing to set up a variable that will hold your registration number (need to know what format the registration number is in (e.g. number, text, etc.)).

Brad.

Here is the gist of it. I've expanded to show the action arguments. My query has [Please enter Reg #]in the criteria field of the column titled Registration #, which is what I am prompting the use to enter. I hope this helps.

Action

OutputTo

Object type query
Object name 2005 Detail (name of the query)
output format Microsoft Excel 97-2003 (*.xls)

OutputTo

Object type query
Object name 2006 Detail (name of the query)
output format Microsoft Excel 97-2003 (*.xls)

OutputTo

Object type query
Object name 2007 Detail (name of the query)
output format Microsoft Excel 97-2003 (*.xls)
Dec 6 '07 #3
BradHodge
166 Recognized Expert New Member
Here is the gist of it. I've expanded to show the action arguments. My query has [Please enter Reg #]in the criteria field of the column titled Registration #, which is what I am prompting the use to enter. I hope this helps.

Action

OutputTo

Object type query
Object name 2005 Detail (name of the query)
output format Microsoft Excel 97-2003 (*.xls)

OutputTo

Object type query
Object name 2006 Detail (name of the query)
output format Microsoft Excel 97-2003 (*.xls)

OutputTo

Object type query
Object name 2007 Detail (name of the query)
output format Microsoft Excel 97-2003 (*.xls)
First, I would suggest taking the "Enter Reg#" criteria out of your Query.

Second, add an unbound txtBox to the form that your button is on (that lauches the output). You could call it RegNum or something like that.

Third, add criteria to your Query that references this new field (e.g. Forms![frmMAIN]![RegNum].

Fourth, add this code to your button...
Expand|Select|Wrap|Line Numbers
  1. Dim strRegNum as String
  2. strRegNum = InputBox("Enter your Reg #")
  3.  
  4. Me.RegNum = strRegNum
  5.  
  6. DoCmd.OutputTo acOutputQuery, "2005 Detail", acFormatXLS
  7. DoCmd.OutputTo acOutputQuery, "2006 Detail", acFormatXLS
  8. DoCmd.OutputTo acOutputQuery, "2007 Detail", acFormatXLS
  9.  
This should do what you are looking for. Let me know how it goes.

Brad.
Dec 6 '07 #4
rccoburn
6 New Member
First, I would suggest taking the "Enter Reg#" criteria out of your Query.

Second, add an unbound txtBox to the form that your button is on (that lauches the output). You could call it RegNum or something like that.

Third, add criteria to your Query that references this new field (e.g. Forms![frmMAIN]![RegNum].

Fourth, add this code to your button...
Expand|Select|Wrap|Line Numbers
  1. Dim strRegNum as String
  2. strRegNum = InputBox("Enter your Reg #")
  3.  
  4. Me.RegNum = strRegNum
  5.  
  6. DoCmd.OutputTo acOutputQuery, "2005 Detail", acFormatXLS
  7. DoCmd.OutputTo acOutputQuery, "2006 Detail", acFormatXLS
  8. DoCmd.OutputTo acOutputQuery, "2007 Detail", acFormatXLS
  9.  
This should do what you are looking for. Let me know how it goes.

Brad.
Thank Brad,

I was using a macro which if you go to the macro tab and double click on it will run. I'm not sure how to make a form. Can you explain? Thanks.
Dec 10 '07 #5
BradHodge
166 Recognized Expert New Member
Thank Brad,

I was using a macro which if you go to the macro tab and double click on it will run. I'm not sure how to make a form. Can you explain? Thanks.
Sure. If you just go to the Forms tab instead. Select NEW and then Design view. When you get the blank slate, use the Toolbox and select the Command Button tool. Drag one onto your form. If the wizard button was also selected, it may try to do the rest of the button for you. Just hit Cancel.

Once you have the button on your form, it will likely say "Command 0" or something like that. Right click on the button and choose Properties. Go to the Other tab, and change it's Name to something that describes it (like "cmdDetailRpt") .

Close the Properties box and then Right Click on the button again and choose Build Event... Code Builder. Between the Private Sub and End Sub statements, put the code that I suggested. Save your form.

Once it is saved, you will be able to go to the Forms tab and open it. Once open, click your new button, and it should do what you wanted.

Once you have it working, you ought to try fooling with the form to add other functions. You could turn the Wizard on (the top middle button on the ToolBox) and drag other buttons or controls onto your form. It will walk you through making them work, then you can look at the code that it came up with.

Good Luck,
Brad.
Dec 10 '07 #6
rccoburn
6 New Member
Sure. If you just go to the Forms tab instead. Select NEW and then Design view. When you get the blank slate, use the Toolbox and select the Command Button tool. Drag one onto your form. If the wizard button was also selected, it may try to do the rest of the button for you. Just hit Cancel.

Once you have the button on your form, it will likely say "Command 0" or something like that. Right click on the button and choose Properties. Go to the Other tab, and change it's Name to something that describes it (like "cmdDetailRpt") .

Close the Properties box and then Right Click on the button again and choose Build Event... Code Builder. Between the Private Sub and End Sub statements, put the code that I suggested. Save your form.

Once it is saved, you will be able to go to the Forms tab and open it. Once open, click your new button, and it should do what you wanted.

Once you have it working, you ought to try fooling with the form to add other functions. You could turn the Wizard on (the top middle button on the ToolBox) and drag other buttons or controls onto your form. It will walk you through making them work, then you can look at the code that it came up with.

Good Luck,
Brad.
Thanks again. I am now getting a compile error method or data member not found. It highlights the statment Me.RegNum when this happens. Any ideas?
Dec 11 '07 #7
BradHodge
166 Recognized Expert New Member
Thanks again. I am now getting a compile error method or data member not found. It highlights the statment Me.RegNum when this happens. Any ideas?
My apologies. You will also need to create a text field on your form (use the ToolBox again). This TextBox will be unbound and will not have anything listed as a Control Source in Properties. Make sure you name this TextBox "RegNum". When you click the button you created, it will ask you for the Reg Number and then will input what you type, into that Text Box. The queries will then draw the Reg Number from the text field on your form.

Brad.
Dec 11 '07 #8
rccoburn
6 New Member
My apologies. You will also need to create a text field on your form (use the ToolBox again). This TextBox will be unbound and will not have anything listed as a Control Source in Properties. Make sure you name this TextBox "RegNum". When you click the button you created, it will ask you for the Reg Number and then will input what you type, into that Text Box. The queries will then draw the Reg Number from the text field on your form.

Brad.

It works! Thanks. Lastly. Can I enter the RegNum in the text field and have it stored in the variable so I don't have to have a popup input box?
Dec 11 '07 #9
BradHodge
166 Recognized Expert New Member
It works! Thanks. Lastly. Can I enter the RegNum in the text field and have it stored in the variable so I don't have to have a popup input box?
You could indeed. It just depends on your work flow. If you are doing multiple reg numbers in a sitting, it might be nice to have the Text Box empty out after each export (just add "Me.RegNum=Null " after DoCmd.OutputTo acOutputQuery, "2007 Detail", acFormatXLS).

Brad.
Dec 11 '07 #10

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

Similar topics

0
1439
by: J Skeggs | last post by:
Hi, Please can someone help me! I have an excel macro which runs a macro in a microsoft access database using the following code: '******************************************** '* This part of the routine runs another routine within * '* MS Access to export data to MS Excel *
0
2461
by: dlieu | last post by:
I've found an odd situation in where the Load event of the active form fires (after the Unload event) when Access is closed. I am able to reproduce this situation in Access 2002 SP3 and Access 2003 on computers running WinXP. This does not appear to happen in Access 2000 on a computer with Win2000. This only seems to happen if there is a hidden form also loaded and, so far, I'm only able to reproduce this if the forms are loaded through...
4
6166
by: mvivar | last post by:
Hi everybody: This will be not easy to explain as my mother language is not english, so my apologies in advance if it sounds confusing. We have a database access 97 wich controls time of people in their job in order to finally know how many money costs us to run some projects. People always estimates the time when reporting and we do have the impression they really underestimate the time.
13
1457
by: Peter L Reader | last post by:
I have to say, from a practical standpoint I'm not all that impressed with the security built into Office 2K3. I'm a small-scale developer building Access apps for a few non-profits locally; I find that in order for me to build and deliver an app that will run without a bunch of scary nag screens, I have to buy a digital certificate from Thawte or somebody for a hundred and a half per year or so...otherwise, they get the "unsafe macro"...
52
9984
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server 2005, and, since he already has licenses for Office Pro 2002, he wants to upgrade to that. I've been saying that we need to upgrade to Access 2003, not 2002, even if Office is kept at 2002. We are also looking to do a fair amount of...
12
2201
by: John Baker | last post by:
Hi: I have read a number of threads on the issue of compressing (compacting) Access data bases programmatically, and have been left confused. We are using Access 2000, and I need code that will programmatically compress an open database. (called "InvoiceManagement.be). Can someone give me a piece of code that will do this, or a pointer to one, please? Thanks
16
6537
by: JoeW | last post by:
I'm utilizing a database that I created within MS Access within a program I've created in VB.NET. I am using the VB front end to navigate the information, but want to be able to print a report, that I've also created within MS Access. I've attempted using the Access.Application instance, but I get errors when it tries to load the database. Just wondering if anyone has any experience with this, and what I should do. Thanks for any...
8
4681
by: Shooter4Life8 | last post by:
I am trying to run a macro from my VB.NET program. Here is my code. Dim myAccess As Access.Application Dim allMacro As String = "ALL-Macros" myAccess.DoCmd.RunMacro(allMacro) I get the error. "An unhandled exception of type 'System.NullReferenceException' occurred in
1
3190
by: sphinney | last post by:
All, I'm not sure how to adequately explain my problem in two sentences or less, so at the risk of providing TMI, here's the condensed verion. I have developed an Access 2002 database file that contains a form, multiple queries and multiple reports. The purpose of the form is to allow the user to run various queries against my company's Sybase server and display a report. Since the queries return ADO recordsets from the Sybase server,...
3
5327
by: White Horse | last post by:
I want to nightly run a VBS Script in Scheduled tasks to open an Access 2003 database and execute a macro. The problem is that the database opens to a switchboard screen. I need to open this database with a VBS script that mimicks opening the database with {shift} open. My code: dim accessApp set accessApp = CreateObject("Access.Application")
0
9636
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
10139
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
10075
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
9931
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...
1
7485
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
5373
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
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
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
2869
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.