Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedding a macro in a Query

Status
Not open for further replies.

THWatson

Technical User
Apr 25, 2000
2,601
CA
My main database has a field called Envelope #. These are for donations. Some people in the main database have Envelope #s and some don't. Periodically a donation is made by a person who doesn't currently have a number, and we need to assign a new Envelope # to that person.<br><br>I have a Query that calls up existing Envelope #'s, and the name of the person to whom that number is assigned. This helps the data entry person know what numbers can still be assigned. But...I discovered that she would then assign a new number and key in the name information right in that Query. This, because the fields are linked by relationship, caused a double entry back in the main database.<br><br>What I would like to do is embed a Message Box macro in a Query, so that every time the Query is run this message will come up, warning the person who enters data not to assign a new number in the Query but only in the main database. But I can't seem to get a Macro to work in a Query.<br><br>Anybody have a solution?<br>Thanks.<br>Tom
 
I would do it slightly differnt.<br>Create a form where all of the emplyees are at.<br>Find the one who you are working with.<br>When they come up have a meesage saying &quot;NO ID&quot; etc.<br>then have it say Press a button called &quot;Get next ID&quot; or &quot;Make an ID&quot;<br>The ID counter would be keep in a separate table.<br>So as a new one was added it would incrament to the next number automatically. (see code below)<br><br>Now when the user is proimpted to Click the Make new ID button it would go to the ID table get the number Add one to it put the new number back in the table for next time.<br>Then also put the current number in the text box on the form called EmployeeID.<br><br>OK<br>-------------------- Add one to number and re-save ---------<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim MyDB As Database, MySet As Recordset<br>&nbsp;&nbsp;&nbsp;&nbsp;Set MyDB = currentdb<br>&nbsp;&nbsp;&nbsp;&nbsp;Set MySet = MyDB.OpenRecordset(&quot;Last-RA-Number&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MySet.MoveFirst<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MySet.Edit<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Temp1 = MySet.Fields(&quot;Last_RA_Number&quot;)<br>' Note Temp1 contains the number<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Temp2 = Temp1 + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MySet.Fields(&quot;Last_RA_Number&quot;) = Temp2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MySet.Update<br>&nbsp;&nbsp;&nbsp;&nbsp;MySet.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;MyDB.Close<br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
Thanks, Doug<br>The only difficulty is that this solution won't quite work. The problem is that we have 3 Envelope # series.<br>One series runs from 1 through 400 - these are the main donors.<br>The second series runs from 700 through 799 - these are pre-authorized remittance donors.<br>The third series is 900 and up. These numbers are for very occasional (maybe even only one time) donors.<br><br>The second and third groups would be no problem to handle the way you suggested, because new Envelope #'s are applied in direct sequence. The difficulty is the first group, those with numbers from 1 through 400.<br>Of these 400, about 275 are applied, and they are not in exact sequence, because some of them have had the same Envelope # for several years. Other numbers have been removed - due to moving away, death, whatever - so there are holes in the sequences.<br>What I plan to do for years 2001 is to change all these numbers so that everything is consecutive, and then your solution will work...but at the moment I am stuck with what we have...so I was hoping I could make this Warning (Message Box warning) that ran when the query was opened.<br>But maybe you can't run a macro in a query, because I can't find reference to that in any manual.<br>Tom<br>
 
Doug<br>In my continuing pursuit of running a macro out of a query, here's what I did.<br>There are 3 existing fields that the query calls up. They are<br>LastName<br>FirstNames<br>Envelope #<br><br>In a fourth field spot in the query design, I added the following<br>Expr1: [DoCmd].[RunMacro]![Macro1]<br><br>Macro1 runs a Message Box that issues a beep and a message that says &quot;Don't enter envelope #'s here. Do it in the main database!&quot;<br><br>This works...but it repeats 3 times...in other words, running 4 times altogether. Why? Is there a way to fix it?<br>Tom<br><br>
 
If you do everyting with code you have Complete control.<br>Now I may not understand completely what you are doing.<br>Typing on a keyboard is Not the best way to communicate.<br>But after using Access for 7 years I know whatever it is it, it can be done in VBA code. With No Messages, No Prompts just click a button and stand back.<br>I would start out by doing one step at at time and getting it to work perfectly. Then go to the next step.<br>It may have to make 4 loops too but it will do it in the background. And VBA code executes in the blink of an eye.<br>Don't try to write the whole thing and then debug a mess.<br><br>Learing VBA will take you to the next level in Access.<br>Mastering VBA will allow you to do thing's that other people will gasp in Amazement.<br><br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
Thanks, Doug<br>All I am trying to do is give the user a message when they run this query. So what I did was create a Macro that ran a Message Box, and now I am running this Macro out of the query. The only trouble is that it's a bit annoying because it runs 4 times. Each of the first 3 times the user has to press the OK button. It works but it's far from efficient...or pretty.<br><br>Do you have a book on VBA for Access that you would recommend?<br>I have looked locally, but can't seem to find one that offers what I would like...and they are expensive.<br>Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top