By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 720 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

coding a command button

P: n/a
Tim
I have one main form that I use to view data as well as add new records.
When I click the add new record button, many of the form's controls that
arn't needed get set to invisible. When I'm done entering the new record, I
want to click on a command button that resets and requeries the form to the
state it is in when it first opens.

What would the VBA code be for such a command button ?
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Tim

In this sort of situation I'll create a private sub behind the form which
automatically hides and unhides the command buttons.

Private Sub ToggleButtons()
If Me.NewRecord Then
Me!CommandButton1Name.Visible = False
Me!CommandButton2Name.Visible = False
etc
Else
Me!CommandButton1Name.Visible = True
Me!CommandButton2Name.Visible = True
etc
End IF
End Sub

List all the buttons that need to be hidden.
Then in the form's On Current and After Update Event Proceedures call the
sub. This way you don't need another button to unhide the other buttons.

Another way to do this with running the code all the time when just
navigating the records would be to create 2 different subs; one to hide the
buttons and the other to unhide them. In the On Current Event call the
HideButtons sub if its a new record and in the form's After update Event
call the UnhideButtons sub.

Private Sub HideButtons()
Me!CommandButton1Name.Visible = False
Me!CommandButton2Name.Visible = False
etc
End Sub

Private Sub UnhideButtons()
Me!CommandButton1Name.Visible = True
Me!CommandButton2Name.Visible = True
etc
End Sub

Private Sub Form_Current()
If Me.NewRecord
HideButtons
End If
End Sub

Private Sub Form_AfterUpdate()
UnhideButtons
End Sub

Hope this helps
Stewart
"Tim" <tg@neo.rr.com> wrote in message
news:xI*******************@twister.neo.rr.com...
I have one main form that I use to view data as well as add new records.
When I click the add new record button, many of the form's controls that
arn't needed get set to invisible. When I'm done entering the new record, I want to click on a command button that resets and requeries the form to the state it is in when it first opens.

What would the VBA code be for such a command button ?

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.