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
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

mdmilner

Well-known Member
Joined
Apr 30, 2003
Messages
1,352
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
 

NitherWise

New Member
Joined
Nov 3, 2002
Messages
36
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
 

mdmilner

Well-known Member
Joined
Apr 30, 2003
Messages
1,352
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
 

Watch MrExcel Video

Forum statistics

Threads
1,126,916
Messages
5,621,602
Members
415,847
Latest member
AlpinoHirsch

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
Top