Object is visible depending on mode

NitherWise

New Member
Joined
Nov 3, 2002
Messages
36
From the switchboard, I have a form that opens in Add or Edit mode depending on what the user wants to do.
I have two labels on the form, one for add mode and one for edit mode. Depending on which mode the form is opened, that is the lable that I want to be visible.

What would be the correct VB code to achieve this?

I have been trying to do this on the On_Load event using If..Then..Else, but have had no success. Either both of them are displayed or neither of them are displayed.

Please advise.

Thanks
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Go backwards a bit to how the user opens it in one mode or the other.
Assuming there's a button that opens it in Edit mode, after the _Click event opens the new form, have it set the Control's .Visible property to the correct settings (set both of them via explicit reference to the form)

You might consider streamlining a bit.
Use a single label and instead change the Text Value of it to Edit/Add instead and not alter the .Visible property.

Mike
 
Upvote 0
It opens from a Switchboard argument.

I was able to get it to work using the code below. Thanks for your help.

Private Sub Form_Open(Cancel As Integer)

If Me.Form.DataEntry = True Then
lblEdit.Visible = False
lblEnter.Visible = True
ElseIf Me.Form.DataEntry = False Then
lblEdit.Visible = True
lblEnter.Visible = False
End If

End Sub
 
Upvote 0
Realized that it was the stock switchboard after I posted but the technique is still valid. Since what you've got works, keep using it. No reason to change - but, you might want to start using your own custom switchboard in the future. It opens the door to alot of options (nothing more than another form)

Also, why remove one of the labels and go with:

Code:
If Me.Form.DataEntry = True Then 
  lblEdit.Caption = "Text to use in Add Mode"
ElseIf Me.Form.DataEntry = False Then 
  lblEdit.Caption = "Text to use in Edit Mode"
End If

Mike
 
Upvote 0

Forum statistics

Threads
1,215,559
Messages
6,125,517
Members
449,236
Latest member
Afua

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top