Results 1 to 4 of 4
  1. #1
    Phred is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    Dec 2009
    Posts
    246

    Force Combobox to go to new record

    Access 2007, not compiled, not split, Windows 7, Moderately Skilled



    I have a Combobox at the top of my Vendor form. You pick the Vendor Name from the box and it displays the Vendor information below.

    I have a command button on my main form "Add New Vendor" - On Click:

    DoCmd.GoToRecord , , acNewRec (The form fields clear and are ready to recieve new vendor info.)

    But the combo box, at the top, still retains the previous Customers Name. I would like to force the combo box to go to a new record as well.

    MyComboBoxName docmd.gotorecord, , acNewRec (code I would like to add but don't know how.)

    MsgBox "Enter Vendor name and data.", vbOKOnly, "Enter New Vendor"
    Forms![frm_main]![SubFrm_Vendors]!VendorName.SetFocus

    After the new Vendor Name is entered, the new record saves and the form refreshes to the new Vendor on the form and in the Combo Box.

    In VBA is there a way to reference a specific control, on a form (combobox), and force it to a new record?

    PHred

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,537
    After:
    MyComboBoxName docmd.gotorecord, , acNewRec

    Try adding this line:
    MyComboBoxName = 0
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Generally speaking, combo boxes are used to select data, not add to it. Is the combo box bound to a field in your form's record source (probably not, if it retains the name)? If not, than you cannot use it to add data to your vendors table. Combo boxes cannot "go to a new record" in any case - they can only update the current record, and only the field they are bound to, if any.

    HTH

    John

  4. #4
    Phred is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    Dec 2009
    Posts
    246
    That did it!

    I have been trying everything.

    I did me.comboboxname = "" (You don't ever want to do this one it disappears the Row Source SQL statement It took me forever to figure that out. And only because June7 told me.)

    But the = 0 doesn't seem to cause any problems. I'm curious to know why?

    But in any event thanks so much. I will be using this several places. Such a simple solution.

    I will mark this solved. Have a great weekend.

    Phred

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 02-28-2012, 09:05 PM
  2. Go to a record that is in a combobox
    By cgclower in forum Forms
    Replies: 5
    Last Post: 11-08-2011, 10:48 AM
  3. use record id in combobox query
    By blaimi in forum Queries
    Replies: 3
    Last Post: 11-04-2011, 11:28 PM
  4. On Add record, how do I force a Save first?
    By KathyL in forum Programming
    Replies: 11
    Last Post: 07-18-2011, 12:37 PM
  5. Replies: 8
    Last Post: 06-22-2011, 10:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums