Results 1 to 4 of 4
  1. #1
    Budatlitho is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Mar 2016
    Posts
    44

    Form using autonumber field for selection and updating

    Hello:
    I have a table, Orders, whose key field is OrderID. The Data Type is AutoNumber.
    Another field in this table is ShipmentID
    I want to display the record by using a Combo Box, whose RowSource is from a query, OrderListQuery, that limits OrderID to records that have not been shipped (ShipmentID Is Null)
    OrderListQuery:
    Code:
    SELECT [Orders]![OrderId] AS Expr1, Orders.ShipmentID, Orders.ShipDate, Orders.LabelId, Orders.Quantity, Orders.OrderDate, Orders.DeliveryDate FROM Orders WHERE (((Orders.ShipmentID) Is Null)) ORDER BY [Orders]![OrderId] DESC;
    Combo Box query is:
    Code:
    SELECT [OrderListQuery].[Expr1] FROM [OrderListQuery] ORDER BY [Expr1] DESC; where Expr1 is OrderID.
    OrderListQuery displays the desired data.
    The Combo Box displays the desired OrderID data.
    However, when attempting to populate the form using the record selected, it errors in that OrderID cannot be set because "control cannot be edited; it's bound to autonumber field "OrderID""
    Form is set as Data Entry: No.
    The record selected is OK, confirmed with:


    Code:
    Private Sub Combo27_AfterUpdate() Debug.Print Combo27 End Sub
    but I cannot get OrderID in the form to accept Combo27 value.

    I believe I could write VB to select the record and update it but it seems like the form should be able to accomplish the same action more easily.

    Hopefully, I'm missing something really dumb, but the hair color of my mustache is beginning to change to that on the top of my head- GRAY! (grin).
    Thanks in advance.

  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    first let's start with .[Expr1] ...that is a default field name due to a duplicate field name or missing field name. Do yourself a favor and establish a valid field name.

    moving on: a form is bound to its record source which can be a table or query. A query may be not editable. This is a standing principle in query design whenever the query is not a 1:1 relationship between table's primary keys.

    So in the form, your selection of the correct record (i.e. not shipped) is a query within the combobox which results in the bound OrderID record that the form moves to - whether or not the form's record is updateable is dependent on its record source query.

  3. #3
    Budatlitho is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Mar 2016
    Posts
    44
    First-- thanks for the quick response.

    I removed the query that restricted the records to 'not shipped'.
    So now the combo box displays all records by OrderId.
    Code:
    SELECT Orders.OrderId AS ID FROM Orders ORDER BY Orders.OrderId DESC;
    debug.print shows correct record.
    When attempting to assign OrderId control as combo box value, I get
    Run-time error, '-2147352567 (80020009)': You can't assign a value to this object

  4. #4
    NTC is offline VIP
    Windows 7 64bit Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    it would seem that you have built your form incorrectly somehow. I presume you have a form that uses table Orders as it's record source.

    if your form is in continuous mode (displaying lots of records) then traditionally the selection of a record is not via a combo box

    if your form is in single mode (displaying a single record): delete your existing combo box; drag a new one into the header of the form and follow the wizard set up to make the combo box select a record

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

Similar Threads

  1. Replies: 1
    Last Post: 12-10-2013, 06:27 AM
  2. Replies: 4
    Last Post: 11-21-2013, 05:06 PM
  3. Replies: 1
    Last Post: 02-02-2012, 08:34 PM
  4. Updating Autonumber Fields
    By Rawb in forum Code Repository
    Replies: 4
    Last Post: 02-21-2011, 07:17 AM
  5. Problems with autonumber field in a form
    By admaldo in forum Forms
    Replies: 0
    Last Post: 02-25-2008, 11:09 AM

Tags for this Thread

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