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

    Unanswered: Possible to preserve a control, issues passing variables

    Hello,

    I have a cmd button to clear a form prior to new order. The way it does this is as follows:
    Code:
    Private Sub beginanorder_Click()
    'Copies fields from original record to variables
    Field1 = Me.custacct
    Field2 = Me.atitle
    Field3 = Me.fname
    Field4 = Me.lname
    
    'Begins a new record
    DoCmd.GoToRecord , , acNewRec
    'Plugs in old values into the new record
    Me.atitle.Value = Field2
    Me.fname.Value = Field3
    Me.lname.Value = Field4

    The problem I have is the compiler complains about 'custacct' because its an autonumber field. Does anyone have another way to preserve specifically the custacct field so it doesn't clear on the 'GoToRecord'.

    Also I need to properly format the passing of a variable in one of my subforms....
    Code:
    Field13 = Me![Order Ship Details Subform].theshipname
    instead, I get an error that it can't find [Order Ship Details Subform]...how should I format it so compiler can find it?

    thanks so much

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    ? are custacct and atitle etc in the same table?
    ...then a new record will take a new autonumber.


    Field13 etc.
    have a go with
    Field13 = Me![Order Ship Details Subform].Form.theshipname

    if still no luck, note that you must address the subform control NOT the name of the form sitting in the subform control - they may not be the same!

    dragging a form into a mother form creates the subform control and automatically gives it the name of the dragged-in form - this can potentially cause confusion if your code later uses .sourceobject to swap the form displayed in the subform control --- you end up with headache-inducing code like
    FieldX = me.frmSub1.form.controlOnFrmSub2 !!!!
    since i regularly swap subforms, i rename my subform controls to soemething neutral like SubFormHole

    to determine the name of your subform control, open the mother form in design-view, open properties window, click ONCE in the subform control and note the Other/Name property ...that's the one you need.

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    What is the error?

    Referring to subforms:
    http://www.mvps.org/access/forms/frm0031.htm
    Testimonial:
    pootle flump
    ur codings are working excelent.

  4. #4
    Join Date
    Aug 2007
    Posts
    102

    Error #2448

    Hi IzyRider and Pootle Flump,

    The error is 2448 -"You can't assign a value to this object"....it's referrring to custacct control(autonum).

    custacct, atitle, etc. are all in the same table supporting the Main Order form. the other controls are in the Order Ship Details Subform.

    By the way I added the '.Form.theshipname' and corrected the naming issue with the subform...it was looking at another name. So thank IzyRider..
    I'm still stuck with the issue of how I can preserve custacct. We have lots of recurring customers, so our goal is NOT to assign a new autonumber everytime they order.

    Each customer is assigned a customer acct# (custacct) through another form and it's stored in table as a Primary number and used in Relationships to connect all new, past orders (for reporting and Invoices).

    When a customer is located through the combo box (unbound)at the start of a new Order, all customer info Order form is populated including the Customer number.

    Thanks for any help..
    Last edited by imrosie; 08-31-07 at 10:36.

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Are you storing the customer details (name, title etc) in the orders table?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    ... and is custacct an autonumber in both the customer and orders tables?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  7. #7
    Join Date
    Aug 2007
    Posts
    102

    No....

    Hi Pootle Flump,

    No, I'm not storing customer details in the Orders table.
    The Main Order form has 2 subforms. The Main form is based on Customer table, with control custacct(CustomerID as autonum).

    1st subform is how the Products are ordered (unitprice, quantity, discount, OrderDetailsID (autonum), OrderID (foreign key))...

    2nd subform (based on Orders table) has Shipping info, ship name, address, city, state, etc, OrderID (autonumber), CustomerID (foreign key)here

    The 2 subforms are 'bridged' together through a hidden control using Link Master Child fields.

    any ideas?

  8. #8
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    So you are running this:
    DoCmd.GoToRecord , , acNewRec
    on your main form which is based on customers when you don't actually want to add a new customer - you want to add a new order? So really you need to go to a new record on your orders subform instead right?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  9. #9
    Join Date
    Aug 2007
    Posts
    102

    Yes,,,,I think the light went on....thanks

    Yes Pootle Flump,

    my only goal is to clear out the subform with the Order Details (productID, quantity, discount, unitprice, etc) and leave the Customer, the Ship Name, etc. alone. Obviously, I'm doing it backwards....thanks

    I think the light went on.....I'll grow up yet as a programmer (background is heavy Unix)...Let me take that thought and get back to this posting.

    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
  •