If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Returning a variable from a query
I have a form that needs to create a unique ID upon entry. Like a new
Sales Order Number for a new sale. What I want to do is run a query that returns the MAX value for a field. "SELECT MAX(SALNUM) FROM TABLE" I can then add 1 to that number and create and a new key. I am having a problem trying to determine how the return the result to a variable. strA = SELECT ...... or some such thing I have tried to look this up in the manual (RTFM) but have not had much luck. Any help appreciated. Thanks Wes |
#2
|
|||
|
|||
Returning a variable from a query
Wes
Try searching on-line or at mvps.org/access for "custom autonumber". Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. You can thank the FTC of the USA for making this disclaimer possible/necessary. "Wes" wrote in message ... I have a form that needs to create a unique ID upon entry. Like a new Sales Order Number for a new sale. What I want to do is run a query that returns the MAX value for a field. "SELECT MAX(SALNUM) FROM TABLE" I can then add 1 to that number and create and a new key. I am having a problem trying to determine how the return the result to a variable. strA = SELECT ...... or some such thing I have tried to look this up in the manual (RTFM) but have not had much luck. Any help appreciated. Thanks Wes |
#3
|
|||
|
|||
Returning a variable from a query
Take a look at the DMAX function
Dim I as long I = DMax("SalNum","Table") Another way I =CurrentDb().OpenRecordset("SELECT MAX(SALNUM) FROM Table").Fields(0) John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County Wes wrote: I have a form that needs to create a unique ID upon entry. Like a new Sales Order Number for a new sale. What I want to do is run a query that returns the MAX value for a field. "SELECT MAX(SALNUM) FROM TABLE" I can then add 1 to that number and create and a new key. I am having a problem trying to determine how the return the result to a variable. strA = SELECT ...... or some such thing I have tried to look this up in the manual (RTFM) but have not had much luck. Any help appreciated. Thanks Wes |
Thread Tools | |
Display Modes | |
|
|