By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,841 Members | 1,757 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,841 IT Pros & Developers. It's quick & easy.

Clear SOME, not ALL controls on a Bound Form

imrosie
100+
P: 222
Is it possible to do this???? My "newbieness" is showing here.

My form is based on a query (customer and order tables). The customers name is first selected in order to fill in data (OrderID, OrderDate, Address, City, Account No. etc.) Unfortunately it also fills in all of the controls(bound and unbound).and specifically the last 'OrderID' and 'OrderDate' and P.O. Number.

To start a new order, I'd like to keep the basic customer info in the controls; i.e. Name, address, city, Acct. number, but CLEAR OUT the P.O. Number, OrderID and OrderDate (bound controls). OrderID is based on an autonumber.

Does anyone have a recommendation? I've looked everywhere, many tutorials. thanks
Rosie
Aug 9 '07 #1
Share this Question
Share on Google+
7 Replies


FishVal
Expert 2.5K+
P: 2,653
Is it possible to do this???? My "newbieness" is showing here.

My form is based on a query (customer and order tables). The customers name is first selected in order to fill in data (OrderID, OrderDate, Address, City, Account No. etc.) Unfortunately it also fills in all of the controls(bound and unbound).and specifically the last 'OrderID' and 'OrderDate' and P.O. Number.

To start a new order, I'd like to keep the basic customer info in the controls; i.e. Name, address, city, Acct. number, but CLEAR OUT the P.O. Number, OrderID and OrderDate (bound controls). OrderID is based on an autonumber.

Does anyone have a recommendation? I've looked everywhere, many tutorials. thanks
Rosie
Hi, Rosie.

There is no need to clear controls on a bound form (unless they itself are unbound), they are being cleared automatically when you go to new record. You need to keep some controls filled with last entered value rather than clear others. This could be easily achieved setting DefaultValue property of a control once the control was updated.
Expand|Select|Wrap|Line Numbers
  1. Private Sub SomeControl_AfterUpdate()
  2.      SomeControl.DefaultValue = SomeControl.Value
  3. End Sub
  4.  
Aug 9 '07 #2

imrosie
100+
P: 222
Hi, Rosie.

There is no need to clear controls on a bound form (unless they itself are unbound), they are being cleared automatically when you go to new record. You need to keep some controls filled with last entered value rather than clear others. This could be easily achieved setting DefaultValue property of a control once the control was updated.
Expand|Select|Wrap|Line Numbers
  1. Private Sub SomeControl_AfterUpdate()
  2.      SomeControl.DefaultValue = SomeControl.Value
  3. End Sub
  4.  

Hi FishVal,

Thanks for your suggestion. I think I understand.......Do I put this in each control's default value line, for the ones' that I want to retain?. Then, when I click the cmd button (the macro that clears the entire form) the person's name, city, addr, etc. would remain? How would I clear the form then, in the case of the next person? When I'm ready to enter a new Order for the next person, would I have information from the previous person
retained in those controls?

Would I need another cmd button if that's the case, to actually clear all controls, including the 'default' values?

I just took a look at the default value line on the form for each control, it does NOT take me into the VB 'code' (to put this routine) it gives me only the option to use Expression Builder. Help

I'm still speaking Newbie here.....
thanks so much
Rosie

Thanks
Aug 9 '07 #3

missinglinq
Expert 2.5K+
P: 3,532
I believe FishVal thought you were entering a record, then wanted to enter a new record with some of the same data. It sounds to me like you're actually pulling up an old record, and then want to create a new record for the same Customer but with order numbers, etc blank; is that correct? If so, put a button on your form and this code behind it:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ClonePartialRecord_Click()
  2. 'Copy fields from original record to variables
  3. NewField1 = Me.YourField1
  4. NewField2 = Me.YourField2
  5. NewField3 = Me.YourField3
  6.  
  7. 'Go to a new record
  8. DoCmd.GoToRecord , , acNewRec
  9.  
  10. 'Plug in old values into new record
  11. Me.YourField1.Value = NewField1
  12. Me.YourField2.Value = NewField2
  13. Me.YourField3.Value = NewField3
  14. End Sub
There's one caveat! None of the fields you're copying to the new record can be the Primary key, because this will throw an error. A Primary Key can only appear in one record!
Linq ;0)>
Aug 9 '07 #4

imrosie
100+
P: 222
I believe FishVal thought you were entering a record, then wanted to enter a new record with some of the same data. It sounds to me like you're actually pulling up an old record, and then want to create a new record for the same Customer but with order numbers, etc blank; is that correct? If so, put a button on your form and this code behind it:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ClonePartialRecord_Click()
  2. 'Copy fields from original record to variables
  3. NewField1 = Me.YourField1
  4. NewField2 = Me.YourField2
  5. NewField3 = Me.YourField3
  6.  
  7. 'Go to a new record
  8. DoCmd.GoToRecord , , acNewRec
  9.  
  10. 'Plug in old values into new record
  11. Me.YourField1.Value = NewField1
  12. Me.YourField2.Value = NewField2
  13. Me.YourField3.Value = NewField3
  14. End Sub
There's one caveat! None of the fields you're copying to the new record can be the Primary key, because this will throw an error. A Primary Key can only appear in one record!
Linq ;0)>
Thank you thank you....you're so right. I'm pulling up an old record, you got it exactly. I'm concerned about the caveat....my orderid is a primary key autonumber in the Order tables (which is a part of the form's supporting query).
I need the OrderID (a new autonumber for each new order), it's used as the foreign key to all the other queries (connecting it also to the CustomerID).....

What can I do in this case....Oh my goodness if this can work I would be ecstatic......you're my hero.thanks

Rosie
Aug 9 '07 #5

missinglinq
Expert 2.5K+
P: 3,532
If orderid is a primary key/autonumber it shouldn't be showing on your form. Autonumbers are supposed to remain in the background or as one guru once said, they're not fit for human consumption! At any rate, even if it does show up on your form, you simply treat that field like you do the one for your Order Numeber, you don't include it in the fields that are assigned to variables and then entered in the new record! When you create the new record Access will generate the new autonumber.

Linq ;0)>
Aug 9 '07 #6

imrosie
100+
P: 222
If orderid is a primary key/autonumber it shouldn't be showing on your form. Autonumbers are supposed to remain in the background or as one guru once said, they're not fit for human consumption! At any rate, even if it does show up on your form, you simply treat that field like you do the one for your Order Numeber, you don't include it in the fields that are assigned to variables and then entered in the new record! When you create the new record Access will generate the new autonumber.

Linq ;0)>
Missinglinq,
this works great! thanks...well on to the next issue. take care.
Rosie
Aug 10 '07 #7

missinglinq
Expert 2.5K+
P: 3,532
Glad we could help, Rosie!

Linq ;0)>
Aug 10 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.