Passing the Variable via Forms (1 Viewer)

Ian Wright

Registered User.
Local time
Today, 07:55
Joined
Oct 20, 2007
Messages
28
I have an Order number register number, i.e. Order number 4564 etc kept in a table from which I have made an form.

When I want to create a new order with next order number I open the form try and take the number and put it in a variable called OrdNo:

DoCmd.OpenForm ("System")
OrdNo = [OrdNo]
DoCmd.Close
DoCmd.OpenForm ("NewOrder")
OurOrdNo = OrdNo+1

I have publicly declared the variable in the module and also tried to do so again in the module. I realise that this might be a bit of an agricultural solution be that as it may, any ideas why it wont load the variable please. :banghead:
 

June7

AWF VIP
Local time
Today, 06:55
Joined
Mar 9, 2014
Messages
5,425
If you want to pass value via a variable between modules, the variable must be declared global or public in a general module header. Other alternatives are TempVars or OpenArgs argument of OpenForm.
 

sneuberg

AWF VIP
Local time
Today, 07:55
Joined
Oct 17, 2014
Messages
3,506
Why not just get the order number directly from the table? Maybe the DMax function would work for you.
 

Ian Wright

Registered User.
Local time
Today, 07:55
Joined
Oct 20, 2007
Messages
28
Hi June,

Many thanks for your kind reply. In the end I added a go to first record command and named the field that I wanted to pick up in it's full name:

DoCmd.GoToRecord , , acFirst
X = Forms![System]![OrdNo]

That did the trick!

Thanks for your advice though :)
 

June7

AWF VIP
Local time
Today, 06:55
Joined
Mar 9, 2014
Messages
5,425
Interesting, since your code closes form System, it should not be available for reference by form NewOrder, which is why I did not suggest referencing back to form System.
 

Users who are viewing this thread

Top Bottom