A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Returning a variable from a query



 
 
Thread Tools Display Modes
  #1  
Old March 17th, 2010, 09:18 PM posted to microsoft.public.access.gettingstarted
Wes[_3_]
external usenet poster
 
Posts: 6
Default 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  
Old March 17th, 2010, 11:17 PM posted to microsoft.public.access.gettingstarted
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default 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  
Old March 17th, 2010, 11:48 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 7,815
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:07 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.