473,404 Members | 2,213 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,404 software developers and data experts.

MS Access Database Macro

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 1909
BradHodge
166 Expert 100+
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
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 Expert 100+
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
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 Expert 100+
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
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 Expert 100+
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
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 Expert 100+
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
BradHodge
166 Expert 100+
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.
And... As I'm sure you figured out, you would delete
Expand|Select|Wrap|Line Numbers
  1. Dim strRegNum as String
  2. strRegNum = InputBox("Enter your Reg #")
  3.  
  4. Me.RegNum = strRegNum
Dec 11 '07 #11
And... As I'm sure you figured out, you would delete
Expand|Select|Wrap|Line Numbers
  1. Dim strRegNum as String
  2. strRegNum = InputBox("Enter your Reg #")
  3.  
  4. Me.RegNum = strRegNum

Everything works great. Thanks again for your help.
Dec 12 '07 #12

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

Similar topics

0
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...
0
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...
4
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...
13
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...
52
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...
12
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...
16
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,...
8
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....
1
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...
3
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...

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.