Reset a form after saving record???

L

Liz

Hi,

I have a problem that probably has a very simple answer (I
hope). After entering and saving the record, my form
(tabs with subforms, some controls not visible ---if then--
etc)does not automatically reset. What I mean is that the
controls that should be invisible are still visible from
the last record saved. How do I reset it back to where it
should be before every record that needs to be entered?

THANKS SO MUCH!!!!

Liz
 
L

Lynn Trapp

Liz,
How are you setting those controls to visible/invisible in the first place?
How are you saving the records?
 
L

Liz

Well, the ones I am referring to are marked with Visible
set to (No) in the prpoerties. If another control (text
box, combo box, etc. ) = (some defined number) then the
control is set to true. For example, here is some code:

Private Sub cbomhhx_AfterUpdate()
If cbomhhx = 1 Then
cboaxisI.Visible = True
cboaxis2.Visible = True
cboaxisIII.Visible = True
cboaxisIV.Visible = True
cbopriorpsychmeds.Visible = True
cbopriorpsychmedsadd1.Visible = False
cbopriorpsychmedsadd2.Visible = False
cbopriorpsychmedsadd3.Visible = False
cbopriorhospmh.Visible = True

ElseIf cbomhhx = 2 Then
cboaxisI.Visible = True
cboaxis2.Visible = True
cboaxisIII.Visible = True
cboaxisIV.Visible = True
cbopriorpsychmeds.Visible = True
cbopriorpsychmedsadd1.Visible = False
cbopriorpsychmedsadd2.Visible = False
cbopriorpsychmedsadd3.Visible = False
cbopriorhospmh.Visible = True


ElseIf cbomhhx = 3 Or 4 Then
cboaxisI.Visible = False
cboaxis2.Visible = False
cboaxisIII.Visible = False
cboaxisIV.Visible = False
cbopriorpsychmeds.Visible = False
cbopriorpsychmedsadd1.Visible = False
cbopriorpsychmedsadd2.Visible = False
cbopriorpsychmedsadd3.Visible = False
cbopriorhospmh.Visible = True
YearmhHospitalization.Visible = False
txtReasonHospitalization.Visible = False


End If



End Sub

I realize there is probably a more streamlined way to
write that code, but I am not very experienced and am way
past my deadline (I am a researcher not a programmer).
Any ideas?

Right now I save the record by clicking a "Save record"
Button or advancing to the next record.

Thanks!

Liz
 
L

Lynn Trapp

Liz,
Saving the record won't cause the combobox's AfterUpdate event to fire. You
may have better luck putting your code in the Form's AfterUpdate event.
Also, I don't see any difference between choices 1 and 2. So, to streamline
it, why don't you do this. Set the visible property of your controls in the
property sheet exactly like you have them for choices 1 and 2. Then, add
your code to the Current event of the form AND to the AfterUpdate event.
You'll want to change the one part like this:

ElseIf Me.cbomhhx = 3 Or Me.cbomhhx = 4 Then
Me.cboaxisI.Visible = False
Me.cboaxis2.Visible = False
Me.cboaxisIII.Visible = False
Me.cboaxisIV.Visible = False
Me.cbopriorpsychmeds.Visible = False
Me.cbopriorpsychmedsadd1.Visible = False
Me.cbopriorpsychmedsadd2.Visible = False
Me.cbopriorpsychmedsadd3.Visible = False
Me.cbopriorhospmh.Visible = True
Me.YearmhHospitalization.Visible = False
Me.txtReasonHospitalization.Visible = False

Also add the "Me." portion to all of your code.
 
L

Liz

Lynn,

Thank you for your help. I have a couple of clarifiaction
questions.

1. The form has approximately 7 tabs (some with subforms,
some not). How would I put the code in the AfterUpdate
event of the form? Would I do it form ALL of the
different controls? If the controls are on subforms, do I
put the afterupdate event there or on the main form?

2. Will putting the coding in the main form's AfterUpdate
event reset the main form? The subforms?

3. Also, I just found a bug. I have a validation rule
that says that the Presentence Date must occur after the
Date of Crime. If I just enter the data in manually, it
works and a msgbox pops up with the rule. If I use a
calendar to pick the date, the validation rule does not
fire. Any thoughts?

Thanks so MUCH, Lynn!

Liz
 
L

Lynn Trapp

1. The form has approximately 7 tabs (some with subforms,
some not). How would I put the code in the AfterUpdate
event of the form? Would I do it form ALL of the
different controls? If the controls are on subforms, do I
put the afterupdate event there or on the main form?

The AfterUpdate event of the subform will fire before the AfterUpdate event
of the main form so, if you need to set properties that are solely on the
subform, then you may want to add your code there.
2. Will putting the coding in the main form's AfterUpdate
event reset the main form? The subforms?

Yes, on both counts.
3. Also, I just found a bug. I have a validation rule
that says that the Presentence Date must occur after the
Date of Crime. If I just enter the data in manually, it
works and a msgbox pops up with the rule. If I use a
calendar to pick the date, the validation rule does not
fire. Any thoughts?

Not sure, but you may rather want to do a validation like that in the Before
Update event of the form, where you have a Cancel parameter and can undo the
form if things aren't like you want them.
 
L

Liz

Thanks, Lynn. I'll give it a try and let you know how it
works. I really appreciate your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top