Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Rangerguy2000's Avatar
    Rangerguy2000 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Location
    Hamilton, ON, Canada
    Posts
    32

    How to load all Product ID's by default

    Hi, How can I make a subfrm load all the Product ID's by default when I open it and I just have to input the quantity ordered.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You use code to batch create records in table. Do you have Orders and OrderDetails tables?

    Something like:

    CurrentDb.Execute "INSERT INTO OrderDetails(OrderNum, Product, OrderDate) SELECT " & Me.OrderNum & " As ON, ProductID, Date() AS OD FROM Products"

    The tricky part is probably committing the Orders record first and grabbing that record's primary key to save as foreign key in OrderDetails.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Rangerguy2000's Avatar
    Rangerguy2000 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Location
    Hamilton, ON, Canada
    Posts
    32
    I have a OrderDetails table that is recording all the data correctly right now but my issue is I want the Product_ID's to load by default when I open the frmMain.

    I have the following:
    frmMain that has Customer Details.
    ProductsTable that has Product_ID's, Names etc.
    frmSub that pulls the Product_ID's from the ProductsTable but it is manual entry, I have to specify the Product_ID every time and then update the quantity.
    I want the frmSub to pull all the Product_ID's from the ProductsTable and their relevant quantity if already ordered from the OrderDetails table

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Conventional structure is: tblCustomers, tblProducts, tblOrders, tblOrderDetails.

    Whatever your db structure, the suggested method still applies, adapt it.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Rangerguy2000's Avatar
    Rangerguy2000 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Location
    Hamilton, ON, Canada
    Posts
    32
    Just dropped a file.
    Pardon me, I used the analogy of Products & Orders but it is really for Drivers & Metrics.
    I used P&O to make it simpler.
    Attached Files Attached Files

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Simplest is to use your real model and not cause confusion with dummy examples. However, as stated, adapt:

    CurrentDb.Execute "INSERT INTO tbl3_MetricDetails(Record_Date, Driver_ID, Metric_ID, Flag_ID) SELECT Date(), '" & Me.cboDriver_ID & "' AS DID, Metric_ID, 1 AS FID FROM tbl4_MetricIDs"

    Then requery the subform to display the new records.

    Me.frmSub_MetricDetails.Requery

    Might want to set the date textbox DefaultValue property with Date()
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Rangerguy2000's Avatar
    Rangerguy2000 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Location
    Hamilton, ON, Canada
    Posts
    32
    Thanks, that worked but I still need to work some kinks.
    The table is auto-populating itself with multiple entries. I guess I have to write some Iif statements for it to look for variables.
    Will update in a few hours from home.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Rangerguy2000,

    How about writing a 5-6 line description of what your database represents --plain English, no jargon?
    Readers find it easier to offer advice/suggestions once they understand WHAT you are trying to do.

    Good luck.

  9. #9
    Rangerguy2000's Avatar
    Rangerguy2000 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Location
    Hamilton, ON, Canada
    Posts
    32
    If you had read the complete post, you would've understood. Take some patience to read & write I guess.

  10. #10
    Rangerguy2000's Avatar
    Rangerguy2000 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Location
    Hamilton, ON, Canada
    Posts
    32
    OK this isn't working. My ask is;
    When I load the frmMain with the inputs Driver_ID and Date; the frmSub should show me all the Metric_ID's and then only inputs I have to make is the Flag_ID's.

    Also the frmSub should update based on new Driver_ID and Date.

    Any help is really appreciated.

  11. #11
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Take some patience to read & write I guess.
    Maybe you like to guess, but we don't.
    When we ask for more information, it's to understand how to help you.

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why isn't it working - error message, wrong results, nothing happens?

    Provide the attempted code.

    Having the records created automatically when form opens to existing records can cause duplication. Use code to prevent.

    Perhaps code should be in the date textbox AfterUpdate event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    Rangerguy2000's Avatar
    Rangerguy2000 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Location
    Hamilton, ON, Canada
    Posts
    32
    1st of all I need to make the mainFrm Driver_ID field as working drop-down (Combobox) work.
    Currently what is happening is, I can only scroll from 1 driver to the next using the next or back built-in access functions.
    as soon as I update a driver with the metrics and want to select the next driver using the Driver_ID drop-dow, access tells me;

    "The changes you requested to the table were not successful because they would created duplicate values in the index, primary key, or relationship."

  14. #14
    Rangerguy2000's Avatar
    Rangerguy2000 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Location
    Hamilton, ON, Canada
    Posts
    32
    Any help is really appreciated on how to make the dropdown list work.

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The combobox works exactly as supposed to. Issue is with your data structure and form design.

    tbl2_Drivers should have only 1 record for each driver - driver should be unique. You have designed this data entry so that selecting driver from combobox edits record or attempts to create new record and results in duplication.

    If you want this combobox to work as a navigation aid, then it should be UNBOUND. Bind a textbox to the Driver_ID field to display this value but don't allow edits in that control.

    I find that the compound key and indexing is causing issues. Also Flag_ID is set as required. I removed the compound key and compound index and set Flag_ID as not required. The INSERT SELECT then works.

    However, the subform query uses INNER JOIN and needs to be RIGHT JOIN. Probably should set Metric_ID and Metric_Name controls as Locked Yes, TabStop No.

    Code:
    Private Sub Record_Date_AfterUpdate()
    If DCount("*", "tbl3_MetricDetails", "Driver_ID='" & Me.Driver_ID & "' AND Record_Date=#" & Me.Record_Date & "#") = 0 Then
        CurrentDb.Execute "INSERT INTO tbl3_MetricDetails(Record_Date, Driver_ID, Metric_ID) SELECT #" & Me.Record_Date & "# AS RD, '" & Me.cboDriver_ID & "' AS DID, Metric_ID FROM tbl4_MetricIDs"
        Me.frmSub_MetricDetails.Requery
    End If
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 02-28-2015, 11:57 AM
  2. Set default value for listbox for form load
    By Delta729 in forum Access
    Replies: 2
    Last Post: 01-11-2015, 12:39 AM
  3. Replies: 2
    Last Post: 08-14-2014, 11:49 AM
  4. Replies: 3
    Last Post: 02-25-2014, 11:46 AM
  5. Replies: 3
    Last Post: 02-26-2013, 05:07 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