additional command button for NEW Record that clears all

G

Guest

I have my form set up that 3/4 of the controls autofill (have an ubound
control with default values = "field names" of what I want to autofill. Then
On Current of the form Call up the autofill) based on the previous record
when the user hits the new record button. I would like to add a command
button that would add a new record but CLear ALL of the fields. Which
happens a few times a day. Any ideas on what code to attach to the on click
event of the new button??

thanks,
BArb
 
J

John W. Vinson

I have my form set up that 3/4 of the controls autofill (have an ubound
control with default values = "field names" of what I want to autofill. Then
On Current of the form Call up the autofill) based on the previous record
when the user hits the new record button. I would like to add a command
button that would add a new record but CLear ALL of the fields. Which
happens a few times a day. Any ideas on what code to attach to the on click
event of the new button??

thanks,
BArb

You can loop through the form's Controls collection setting the value of each
to null. You'll need to trap the error if you try to Null a control that has
no value (such as a label or a yes/no field), or else check the control type
first.

The fact that you need to do this is a bit unsettling: it sounds like you're
routinely storing lots of repeating data. Often such data should be in the
"one" side table of a one to many relationship, and should only be entered
once. What's the reason for the extensive autofilling?

John W. Vinson [MVP]
 
G

Guest

John,

Thanks for your help - the person inputting the info - groups the Trucking
Tickets by Client and date- Alot of the info is the same but the Truck# and
the lbs of material is different - so they need to assign a new ticket with
the new truck- pretty much working okay - I understand your concern though.

Any input on the way the VB code would look for the On click event of the
NEW RECORD Button-

Thanks again,
Barb
 
J

John W. Vinson

Any input on the way the VB code would look for the On click event of the
NEW RECORD Button-

Private Sub cmdNewRecord_Click()
DoCmd.GoToRecord acForm, Me.Name, acNewRecord
Me!thiscontrol = Null
Me!thatcontrol = Null
Me!theothercontrol = Null
<through all the controls>
End Sub

John W. Vinson [MVP]
 
A

Amber LaMonte

You need to add a command button to the form. Before you do that make sure that you have highlighted the control wizard button. Place the button where you want it and you will get a wizard that will have a selection on the left side of the wizard that will say "Categories" under catagories select "Record Options". On the right side of the wizard under "Actions", select "Add New Record".

This will result in a new blank wizard.

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
G

Guest

John,
I put the code below attached to a command button but when I click it it
goes to the second to last record - not to a new records- not sure what I am
missing. Had to change the text fields to " " - it didn't like the null.

Any ideas. and put quotes around form name - probably something wrong there
too???

Thanks,
Barb




Private Sub cmdNewRecord_Click()
DoCmd.GoToRecord acForm, "comboticketentry2(newone2)", acNewRecord
'Set all autofill fields to null when hit New Record button
Me!cboClientId = " "
Me!cbojob = " "
Me!ServiceDate = Null
Me!cost = Null
Me!cboPit = " "
Me!Comments = " "
Me!cboactpit = " "
Me!OverallMarkup = Null
Me!CartageRate1 = Null
Me!TruckCartageRate1 = Null
Me!TaxRate = Null
Me!Taxex = " "
Me!FuelperRate1 = Null
End Sub
 
G

Guest

got it BUT now where it put the " " for the text fields- there is a Blank
space there that I don't want. So I just put "" with no space but back in
the design view of the table I have do not allow for zero length strings.
not sure how to get around this - I know I can change it to say yes allow for
0 length strings but afraid it might get me in trouble later. would really
like it to allow for zero length strings on NEW records only. Not sure how to
work this code in or what exactly and where to put it. Any help???

Thanks,
Barb
 

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