Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2007
    Posts
    102

    Unanswered: How to clear some, Not all controls on a Form

    Hi,

    I have a form bound to a query (customers, orders). I 1st locate the customer (via combo box rowquery). The info fills in most of the controls, including the old OrderNum, and OrderDate. In order to begin a new Order (within the subform), I'd like to CLEAR out all controls, except the customers' acct number, address, city, state and companyname.

    The controls I want to clear are bound and unbound (old orderID, orderDate, PO number). Trouble is the OrderID is based on an autonumber on the form.

    I had to resort to a macro (with OpenForm set and 'new' record on click, in order to clear out the entire form (both bound and unbound)).......but that's not really what I want to do.I lose the Customer's name etc.

    Does anyone have a suggestion?

    thanks

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Assign values you wish to save into variables before you run yuor macro, then populate the controls with the stored variable values.
    George
    Home | Blog

  3. #3
    Join Date
    Aug 2007
    Posts
    102
    Ok Georgev,

    I know, I should have been more specific on "does anyone have a suggestion AND example". Do you?

    I'm not sure I understand your suggestion, without an example.

    What I have is a cmd button (on my Order form) that runs a macro to 'clear' the entire form on 'click'. It does a great job. I only resorted there after trying some "Me.Undo's", that didn't clear the bound controls. In which event exactly would I store the variables? Since the cmd button stands alone, I'm not sure?

    thanks
    Last edited by imrosie; 08-09-07 at 07:56.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    Dim Sname As String
    Dim FName As String
    
    SName = Me.txtSurname.Value
    FName = Me.txtFirstname.Value
    
    '<insert your code that clears the fields>
    
    Me.txtSurname.Value = SName
    Me.txtFirstname.Value = FName
    Feel free to ask any questions
    George
    Home | Blog

  5. #5
    Join Date
    Aug 2007
    Posts
    102
    Hi GeorgeV,

    I completely understand what you're doing. However, where you tell me to insert "code here" It's not actually VB code. My cmd button uses a macro (it's part of a macrogroup for this form) in an 'on click' event.

    when I go into the control properties, to the the event 'on click' there is this on the line only:
    'Add an Order and Details.CreateNewOrder : On Click'

    In the macro event the action is this 'go to record' and the setting is new (for a new record) which clears the entire form. So there is no VB 'code' event. I'm a newbie, so maybe I'm missing something here. help.

    Should I put a 'docmd.clear for or go to record acnew in place of the macro...?

    thanks
    imrosie

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by imrosie
    where you tell me to insert "code here" It's not actually VB code. My cmd button uses a macro
    Code:
    DoCmd.RunMacro "MacroName"
    Or alternatively you can convert your Macro to VBA code by right clicking the macro and doing a save-as... Module. Then you can nick the code and stick it where you want

    EDIT: I prefer method 2
    George
    Home | Blog

  7. #7
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    I'm with george. Since you're a "newbie", I'd suggest you start out NOT using macros. They're just bad practice. Based on some of your other posts, you already have used some VB. Best to just continue using VB for everything.

    Code:
    Private Sub MyButton_OnClick
    Dim strName as String, strAddress as String
    'get the values to reuse
    strName = Me!txtName
    strAddress=Me!txtAddress
    'move to a new record
    DoCmd.GoToRecord , , acNewRec
    'now drop the reused values back in
    Me!txtName=strName
    Me!txtAddress=strAddress
    Exit Sub
    Inspiration Through Fermentation

  8. #8
    Join Date
    Aug 2007
    Posts
    102
    RedNeckGeek, Georgev, you guys are great! I love this....I'm going off to try this out now (using option 2)...I like VB too, instead of the macro's...

    I'll report back for the sake of others

    imrosie

  9. #9
    Join Date
    Aug 2007
    Posts
    102
    Hi Georgev and RedNeckGeek,

    I tried it and had a little problem, but it's working now with this:
    Code:
    Private Sub beginanorder_Click()
    NewField1 = Me.custacct
    NewField2 = Me.atitle
    NewField3 = Me.fname
    NewField4 = Me.lname
    NewField5 = Me.TheCompany
    
    'Go to a new record
    DoCmd.GoToRecord , , acNewRec
     
    'Plug in old values into new record
    Me.custacct.Value = NewField1
    Me.atitle.Value = NewField2
    Me.fname.Value = NewField3
    Me.lname.Value = NewField4
    Me.TheCompany.Value = NewField5
    End Sub
    It's working like a charm....I took your idea of the macro code inside VB. thanks
    imrosie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •