Form back to default/Opening State

Tupacmoche

Registered User.
Local time
Today, 12:03
Joined
Apr 28, 2008
Messages
291
Hi Form Masters,

I have a relatively complex form that hides many things (subforms, textboxes, ect) using its OnLoad event. But, as I update or add new records the "hidden" objects remain open. Is there another event that, I could use to reset the form back to its onload state without actually reloading it?
 
I normally make functions that do this kind of thing.

In OnLoad I'd call "TCO_PrepForm" (a sub I create) to do all of the preparatory work. Then if I need to reset, I could call TCO_PrepForm from where ever it is needed.
 
What does hidden objects remain open mean?
Do you mean remain visible?
 
Mark,

So, if I understand you correctly what you are suggesting is as follow: Here is the OnLoad code for my form:

Me.btnMedStewForm.Visible = False
Me.btnHelp.Visible = False
Me.Label_TabExit.Visible = False
Me.LblTextInstructions.Visible = False
Me.DonorAdvanceID.SetFocus
Me.btnTest.Visible = False
Me.Notification_subform.Visible = False
Me.GiftAllocations_subform.Visible = False
Me.SoftDonorInfo_subform.Visible = False
Me.GiftID.Visible = False
'---------------
Me.Box21.Visible = False
Me.Box13.Visible = False
Me.SecStockName.Visible = False
Me.SecTicker.Visible = False
Me.SecNumofShares.Visible = False
Me.SecHigh.Visible = False
Me.SecLow.Visible = False
Me.SecAve.Visible = False
Me.SecValue.Visible = False
Me.GiftWireAmt.Visible = False
Me.GiftCheckNo.Visible = False
Me.GiftRecptDt.Visible = False
Me.GiftCkAmt.Visible = False
Me.GiftCashAmt.Visible = False
Me.GiftCreditCardNum.Visible = False
Me.GiftNameonCard.Visible = False
Me.GiftCardExpDt.Visible = False

So, put this into a Sub like TCO_prepform and call it when, I need to redraw the form?
 
Well you answered me indirectly!
To follow Mark's idea you would indeed put all that code in a sub.
I also use that method regularly and it works well.

Another method is to use the controls tag property.
Set all controls to have the same tag value e.g. H ... for hidden.
Then you just need one line of code
Code:
ShowControls False, "H"

The ShowControls function together with LockControls and EnableControls variations can be found in this example database https://www.access-programmers.co.uk/forums/showthread.php?t=293439
 
In essence, YES...

That said I would also take a look at your naming conventions for controls. Me.Box21 doesn't really tell me what you have in it.

I would also break the controls out by general groups, such that you turn on/off sets of controls together. This way TCO_PrepForm would call several other subs, each of which turns on/off a group of related controls. You would also have matching subs to turn off/on the same groups of controls when needed, including setting default values as required.
 
Ridders,

This implementation of very cool thanks! I would like to expand on my question since it is relevant to my form. On part of my form, I have a section for payment type. Examples are Check, Cash, Credit Card, ect. Since, I did not want all of these payment methods cluttering up the form, I set up a Combo box for payment types. So, if you select Check in the Combo box then the three text boxes for collecting check information are set to visible. The same is true for Cash, Credit Card and many others. Now, to the issue at hand. All of these controls occupy the same space on the form. I literally placed them on top of each other but since only a logical set of them are visible at any given time they work fine. Is there a better way to implement this that you are aware of? I was thinking of a completely code based approach that had the coordinates and position of each set of payment methods that would be painted onto the form (with code of course) as needed.
 
You can also use the tag property for this. It's a very versatile approach
Set the tag property for each payment type control as e.g. CA, CH, DD etc

Set all types hidden by default in one command in your Form_Load event e.g.
Code:
ShowControls False, "CA", "CH", "DD"

Then in the after update event of your combo use code like this
Code:
'reset all controls hidden
ShowControls False, "CA", "CH", "DD"

'now show controls specific to each payment type
Select Case Me.cboPaymentType

Case "Cash"
    ShowControls True, "CA"
Case "Cheque"
    ShowControls True, "CH"

...etc for other payment types

End Select
 
Do you save payment method in the same table or is this a child record?

You may want to look at "Well, I've got some of it on me, but I want to charge the rest" type issues.

For myself, payments are always in their own files and, if needed, reference other tables for specific types of payment (CC transaction, ACH transaction, ect). I've had too many cases in the past where someone wanted to do something... unusual... to try and force only one source of payment for a transaction. Debit - type gift cards can be the bane of your existence if you do not prepare for this ahead of time.
 
Hi ridders,

What can you say about placing the objects on the form?:rolleyes: The code will only turn them on or off.
 
Hi ridders,

What can you say about placing the objects on the form?:rolleyes: The code will only turn them on or off.

Why do you need to do so?
Place them in the position you want them & then hide until needed

Otherwise you can use Control.Move code e.g.
Code:
Me.Command14.Move  1000, 200, 1000, 500
where the syntax is ControlName.Move (Left, Top, Width, Height)

See https://msdn.microsoft.com/en-us/vba/access-vba/articles/control-move-method-access?f=255&MSPPError=-2147217396

I haven't got code to move a batch of controls all at once as I don't bother doing so using my approach. A Google search may throw up something
 
ridders,

Is there an Access function that can return the position of an object on the form?
 
Several: .Left, .Top, .Width, .Height where all values are in TWIPS
e.g. Me.ControlName.Left
 
.Left, .Top, .Width, and .Height are all read/write. You can use
Code:
Variable = ControlName.Left
ControlName.Left = (Variable + Offset)

[B]OR[/B]

ControlName.Left = ControlName.Left + Offset

to move a control a given distance from its starting place without knowing where it was to begin with. .Move changes the position without giving you the initial value.

Code:
ControlName.Move = ControlName.Left + Offset

Both work equally well but .Move may be much better for reminding yourself exactly what you are doing.

For conversion, there are 1440 TWIPs per inch / 567 per cm .

Still wondering if your business model is such that you would accept multiple partial payments though. I bring this up because it is rather a pain to have to change this in the future.
 
Hi Ridders,

Just back from vacation where do, I put this code? ShowControls False, "H" In OnLoad?
 
Yes. See post 8.

You can also show/hide various controls at other times.
E.g depending on the result from a combo box you might want certain controls to be hidden or shown.
So you would use if...else..end if code in your combo after update event.
Or if preferred, use select case statements
 
Without having the details of what you are making visible when, you may also need to place the code in the form's current event. Right now your cods is just a blast and it is in the load event which runs only ONCE. By simply moving the code to the Current event, each record you move to would be reset to the default.

However, you may want the code to be smarter and so rather than simply making default settings, perhaps you want to include some logic so when you scroll to existing records, items are visible or invisible based on the current values.

So the code might look like:
Code:
If sometest Then
    Me.btnMedStewForm.Visible = False
Else
    Me.btnMedStewForm.Visible = True
End If
If Sometest2 Then
    Me.btnHelp.Visible = False
else
    Me.btnHelp.Visible = True
End If
If Sometest Then
    Me.Label_TabExit.Visible = False
    Me.LblTextInstructions.Visible = False
Else
    Me.Label_TabExit.Visible = True
    Me.LblTextInstructions.Visible = True
End if

So you can combine the settings as necessary. Perhaps only one condition might control 3/4 of the fields. We don't know but you do.

PS - if you are having to set focus to the first control, you might want to fix the tab order so that Access handles that for you. Remove any locked fields from the tab order entirely so that the focus passes over the field when you are tabbing. You can still click into a field if you need to.
 

Users who are viewing this thread

Back
Top Bottom