Best way to store info on a form

Clearing a bound field implies changes to be made to the underlying record. However, if you are creating a new record bound to a form, Access should clear the record and then the Access part of the Current event will load the controls with an empty record.

Clearing an unbound control isn't hard if at least some of the controls ARE bound so that you can have a Current event. However, if the entire form is unbound, there will be no Current event because there is no recordset with which to synchronize. In that case, your data flow gets considerably more complex.

Specifically to clear a combo box that doesn't have a default value, you could try a comboboxname.Undo - which should reset it to "no selection."
Every control on the form is bound and at this point I have to leave it that way. Undo doesn't work.
 
It appears that I did understand and have been able to make this work!!!! YAY but now I need to clear the Employee Name (a combo box) but when I tried DefaultValue = 0 for that it did not clear the field. Any thoughts on how to clear this one field?
I don't understand something. Before you used the code to assign the default values, what were showing up for the Employee Name? What happens if you don't assign any code for it?
 
Every control on the form is bound and at this point I have to leave it that way. Undo doesn't work.

Is the control source (.RowSource) for the combo box taken from the same table that is the .RecordSource for the form? It is likely that you can't clear the combo unless you allow it to be empty. That comes from a mix of its properties and the .RowSource for that combo.
 
I posted on Wednesday but apparently it did not save my post - or at least I can't find it. I thought I had this working but realized the form was staying on the current record so if I changed the employee name it simply replaced the info for that record. I need this to go to a new record but when the new record opens all fields except the Employee Name maintains the info that was from the record that just closed. Maybe I was't clear in my requirements but I know I am not getting the results I had hoped for.
 
I posted on Wednesday but apparently it did not save my post - or at least I can't find it. I thought I had this working but realized the form was staying on the current record so if I changed the employee name it simply replaced the info for that record. I need this to go to a new record but when the new record opens all fields except the Employee Name maintains the info that was from the record that just closed. Maybe I was't clear in my requirements but I know I am not getting the results I had hoped for.
Are you able to post a sample db, so we can see what's happening?
 
I thought I had this working but realized the form was staying on the current record so if I changed the employee name it simply replaced the info for that record.
You cannot use a bound control as a search field. Why? Because changing the value just changes the current record as you discovered. You need to add an unbound control. If you have the wizards active, there should be an option about how to use a combo if you add one.
 
Ok so this is another DUH moment for me - I missed the part of putting it in the afterupdate, I was putting the code in the wrong place. After taking a break from this and looking at it with fresh eyes I realized I had similar code elsewhere in the form and was able to use that and adapt it for this need. So now I have the button to add more by procedure working correctly.

BUT now the clear form button is not clearing the form - the afterupdate that is set above triggers after the clear button. Not sure how to set the default value of these back so the fields are blank. I will continue to poke at this but if someone understands and knows the fix please post.

Thanks as always!
 
Ok so this is another DUH moment for me - I missed the part of putting it in the afterupdate, I was putting the code in the wrong place. After taking a break from this and looking at it with fresh eyes I realized I had similar code elsewhere in the form and was able to use that and adapt it for this need. So now I have the button to add more by procedure working correctly.

BUT now the clear form button is not clearing the form - the afterupdate that is set above triggers after the clear button. Not sure how to set the default value of these back so the fields are blank. I will continue to poke at this but if someone understands and knows the fix please post.

Thanks as always!
To clear the form I am currently using If Me.Dirty Then Me.Undo
 
To clear the form I am currently using If Me.Dirty Then Me.Undo
Sorry - should have tested my theory on this before posting the question. It appears by putting the following before If Me.Dirty Then Me.Undo it does reset the values and clears the fields.
Me.DateComplete.DefaultValue = ""
Me.TimeCompleted.DefaultValue = ""
 
Sorry - should have tested my theory on this before posting the question. It appears by putting the following before If Me.Dirty Then Me.Undo it does reset the values and clears the fields.
Me.DateComplete.DefaultValue = ""
Me.TimeCompleted.DefaultValue = ""
Just in case you weren't aware, just because you see something on the form because of the Default Value, it doesn't mean the form is Dirty or the table has those values in it already. Right?
 
I want to thank everyone who helped on this problem. It appears that I have the form working exactly as I need it to. You are wonderful - all of you!
 
What did you do to get the effect you wanted?
I added this to the afterupdate on the form (this is the coding I found that was used previously elsewhere in the datebase and it work!

Const cQuote = """"
Me.DateCompleted.DefaultValue = cQuote & Me.DateCompleted.Value & cQuote
Me.TimeCompleted.DefaultValue = cQuote & Me.TimeCompleted.Value & cQuote
 
Last edited:
I added this to the afterupdate on the form (this is the coding I found that was used previously elsewhere in the datebase and it work!

Const cQuote = """"
Me.DateCompleted.DefaultValue = cQuote & Me.DateCompleted.Value & cQuote
Me.TimeCompleted.DefaultValue = cQuote & Me.TimeCompleted.Value & cQuote
OK, that's what DBGuy and Gasman were trying to tell you in posts 2 and 10. Glad you got it working the way you wanted.
 

Users who are viewing this thread

Back
Top Bottom