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

Changing the look of a form used for both adding and editing

Status
Not open for further replies.

KerryL

Technical User
May 7, 2001
545
US
In my database, the "add" and "edit" switchboard buttons open the same form.

Clicking on "Add" opens frmCustomerData in add mode, clicking on "Edit" opens frmCustomerData in edit mode.

When opened in edit mode I would like the user to be able to select a customer record (for editing) from a combo box named cboCustomerName. However, when the form is opened in add mode, the combo box should not be available (not visible).

If I add the following line into the code behind the "Edit" switchboard button will that do the trick?
frmCustomerData.cboCustomerName.Visible = True



And for the "Add" button:
frmCustomerData.cboCustomerName.Visible = False


Or is there more to it than that?


 
Hi!

It will work if you put Forms! in front of what you have.

hth Jeff Bridgham
bridgham@purdue.edu
 
A more conventional approach would be to place a "symbol" in the Tag property of the form, and check the tag in the onload (or even the on activate) event. Set your cbo.visible based on (or even equal to the Tag)

So, if you place a 0 ("Zero") in the Tag, The following will make the combo box NOT visibe, while any other value will make it visible.

e.g.

Me.cboCustomerName.Visible = Val(Me.Tag)

If this is unapealing, you can still the tag property with text. Assume that the tag.text = ["Add" | "Edit"], then

Me.cboCustomerName.Visible = (Me.Tag = "Edit")


MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Another option is to add a hidden field in the switchboard and on button press send a key word to the field like "add" or "edit"

then hide the switchboard rather than close it. Allow your new form on open to check the value of the field in switchboard.

If value = "add" then
me.combo1.visible = False

Elseif
me.combo1 = " edit" then
me.combo1.visible = True

EndIf
End sub

Hope it helps

zero
 
I have some issues w/ the "zero" approach.

First, it un-necessarily adds a control. along with the attendant issues of dealing with the Hidden object.

Second, it REQUIRES that additional objects be instantiated in the application. If someone attempts to just "USE" the (Add/Edit) form, they will get an error. Passing the Status value to the form avoids any error. It just has a "default" mode.

Third, the Block if is un-necessary. Although an "IF" is executed, it is not necessary to explicitly do the Block, as the simple assignment will accomplish this.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top