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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Static Variable in Extra Macro 1

Status
Not open for further replies.

brandewie7

Technical User
Jan 25, 2004
6
US
I am trying to have the default value of an inputbox equal the value of the last answer of the inputbox. For example:

Static DefaultAccount
dim question as string
question = inputbox("What account?",,DefaultAccount)
defaultaccount=question

This first time the macro is ran it should be blank. After the user enters an account number, and runs the macro a second time, the first entered account should be the default.

I have done something similiar to this in Access. Although with access, I was able to use ADO to update a value in a table, and then use that value after the form was closed. I am trying to use an Extra macro, so a key can be assigned to run it. I hope this makes sense. Thanks for your help in advance.
 
One way to do this would be to store the value in a text file. The file would be blank the first time, and then store the value the user keys in. This value could then be used as the default value the next time round.

Any use to you?
 
Thanks for your help. I am not sure how to store the value in a text file. Can this be done with ADO or DAO? Thanks for your help.
 
Choose a convenient location in place of c:\yourfile.txt, and use something like...

Code:
'To save the account for next incarnation...
FileNo%=FreeFile()
Open "c:\yourfile.txt" For Output as #FileNo
  Print #FileNo, DefaultAcct$
Close FileNo

'To retrieve it from last time
FileNo%=FreeFile()
Open "c:\yourfile.txt" For Input as #FileNo
  Input #FileNo, DefaultAcct$
Close FileNo
 
It will be reset to nothing when every instance of EXTRA! Personal Client is closed.

Code:
Global LastAccountUsed As String

Sub Main()
  Dim Account As String

  Account = InputBox("Please enter account below:", , LastAccountUsed)
  If Account = "" Then
    ' Assume cancelled or nothing entered
    Goto Terminate
  End IF

  LastAccountUsed = Account

  ' Do stuff
Terminate:
  ' Cleanup, reset System variables if changed, etc.
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top