Making fields blank after focus leaves them

ledmark

Ledmark
Local time
Today, 02:56
Joined
Mar 11, 2008
Messages
127
Hello again - I have built an Option Board in which a patient's Name, SSN and Date are entered. Then a person clicks a command button to enter a form. Once they fill out the form and close it, it takes them back to the Option Board.

What code would need to be written so that the information entered would be deleted. I want the Name, SSN and Date text boxes to go blank after the user exits the form and comes back to the Option Board? Would it on in the "On Lost Focus" event? Can someone help me with the code for this?

Thanks for any help.
Laura
 
Hi Laura,

Assuming you have a close command button on the form, try placing this code in the close button, this code should blank out the text boxes, and return to the Option Board:

'Purpose: Clear all the search boxes in the Form Footer, and show all records again from the details form.
Dim ctl As Control
'Clear all the controls in the Header section
For Each ctl In Me.Section(acHeader).Controls
Select Case ctl.ControlType

Case acTextBox
ctl.Value = Null

End Select
Next
'Turn the forms filter off
Me.FilterOn = False

David,
 
Thank you so much David for your help. I'll try it today and let you know what happens.

Laura
 
Hello David - so this did not work at all. I see that in the code you are asking it to clear text boxes in the Header and Footer of the form but the text boxes are in the detail section of the form. Does that make a difference? Do I need to put the field names anywhere in the code?

Thanks
Laura
 
Hey David - as I look at what you wrote I'm thinking you misunderstood what I'm trying to do. The text boxes with the Name, SSN and Date are on the Option Board in the detail section of the form and after filling out those three text boxes I click on other command buttons to take me to other forms where the Name, SSN, and date are auto-filled.

What I'm trying to do is after I use the option Board information on another form, when I leave that form and go back to the option board to do another patient - I want the three text boxes to be blank again instead of having the last person information in it.

I'm hoping this makes more sense.

Thanks for your help.

Laura
 
What I'm trying to do is after I use the option Board information on another form, when I leave that form and go back to the option board to do another patient - I want the three text boxes to be blank again instead of having the last person information in it.

When you 'go back to that form', you could simply do a docmd.gotorecord,,'that form',new record

That's off the hip, so maybe not perfect.
 
Please change:
For Each ctl In Me.Section(acHeader).Controls

to:
For Each ctl In Me.Section(acDetail).Controls
 
You probably won't need to put in the text field names, if Name, SSN and Date are the only text boxes in the detail section.
 
Laura,

Also for the code:

Me.Section(acDetail).Controls

Change the Me. part to the Option Boards form name. By default it will be frm.
 
Thank you so much for all the replies - I'll give it a try to see what happens.

Laura
 
David - I got it to work so thank you very much for your help. This is what the final code was:

'Purpose: Clear all the search boxes in the form Footer, and show all records again from the details form.

Dim ctl As Control

'Clear all controls in the Detail section
For Each ctl In Forms!frmOptionBoard.Section(acDetail).Controls
Select Case ctl.ControlType

Case acTextBox
ctl.Value = Null

Case acComboBox
ctl.Value = Null

End Select
Next
'Turn the forms filter off
Me.FilterOn = False

DoCmd.Close

Woo-Hoo!! Thanks again :)
 

Users who are viewing this thread

Back
Top Bottom