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

declaring constants 3

Status
Not open for further replies.

obulldog27

Programmer
Apr 26, 2004
169
0
0
US
I have a form with two buttons. One to add a record and one to display the records. When the user clicks on add record the records displayed go blank to allow the user to do data entry. What I want is for the user to click on the add record again when he is done with the data entry to actually add the record to the database.

My idea is to add a constant called temp which will keep track of the add record button clicks. one click to make the textboxes go blank (if temp = 1) and another to actually add the records to the database (if temp =0).

I am not familar on how to declare the constant.
 
At the modular level delcare as follows
Code:
Private ClickNumber as integer
You can also use a static varialble with in the button click event,
Code:
Static ClickNumber as integer

>a constant called temp
Isn't that a contradiction in terms. It may cause confusion later on for you and other developers. I would recommend a more descriptive variable name.

zemp
 
Particularly since we are not talkng about a constant...
 
If you want to achieve this solely in the lifetime of one form, then use a form-level variable. At the top of the module, just after Option Explicit:

Option Explicit
Dim intTemp as Integer

Or, if this is always in the Command_Click event, you can use a Static.

Private Sub Command1_Click()
Static blnSave as Boolean
'defaults to False
If blnSave Then
'do your save stuff
Else
' do your blanking stuff
End If
blnSave = Not blnSave
End Sub

For reference on constants, see VBHelp

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
One good solution would be 2 change the caption of your button
this way the user is clear of what's next action would be.


Private Sub Button1_Click()
With button1
If (.Caption = "&Save") Then
If (AddedNewRecordSuccess) Then
.Caption = "&Add Record"
Button2.Enabled =True
End if
Else
.Caption = "&Save"
Button2.Enabled =False
End if
End with
 
VL99 -

Probably best in your approach to set up a constant:

Private Const cstrSave as String = "&Save"

Then you can use the constant both to test the caption and to set it. That will avoid any problems due to typos or later changes to the button caption.

Glenn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top