Results 1 to 7 of 7
  1. #1
    RichH is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    3

    INSERT INTO Skipping Rows

    Hi all,



    I have a function that adds records to a temporary table (tmpCart), which is then transferred to another data table (tblCheckOuts) once a user clicks the Check Out Button. I'm having some issues where the function that adds those records to the main table. It seems to be writing over some of them or deleting them with the next record in the temp table.

    For instance, the tmpCart may have eight records, each having a movie id, kiosk id, and inventory id. The tblCheckOuts contains an auto number, customer ID, movie ID, kiosk ID, inventory ID, check out date, and a few yes/no fields used in other functions. The table currently has 179 records. When the strSQL runs, it may add the first two records in the tmpCart, increasing the record count to 181. It may then back up a row and add in record #182 where 181 was so now the record count goes "178, 179, 180, 182" I don't know how or why it's doing this... Here's the code below. Any help would be appreciated.

    Code:
    Private Sub cmdCheckout_Click()
        Dim strUser     As String
        Dim strKiosk    As String
        Dim strMovie   As String
        Dim strInvty    As String
        Dim lngCartCnt As Long
    
    '   Initialize the variables
        strUser = Me.OpenArgs
        strKiosk = Me.frmCart.Form!Kiosk
        strMovie = Me.frmCart.Form!Movie
        strInvty = Me.frmCart.Form!Inventory_ID
        
        lngCartCnt = GetCartCnt
    
    '   Confirm there are items in the cart
        If lngCartCnt = 0 Then
            MsgBox "Your cart is empty", vbInformation, "No Items in Cart"
        Else
    '       Delete any selected titles and requery the subform
            DeleteTitle 'Function to delete any items in the cart that have been marked for removal
               
            strSQL = "INSERT INTO tblCheckOuts ( Customer, Movie, Kiosk, [Inventory ID], [Check Out Date]) SELECT '" & strUser & "', tmpCart.Movie, tmpCart.Kiosk, tmpCart.Inventory_ID, Date() AS CheckoutDt FROM tmpCart"
            
    
    '       Execute the SQL
            CurrentDb.Execute strSQL
            
    '       Initialize the SQL to update movie status
            strSQL = "UPDATE tmpCart INNER JOIN tblInventory ON tmpCart.Inventory_ID = tblInventory.[Inventory ID] SET tblInventory.Status = 'Unavailable'"
            
    '       Execute the SQL
            CurrentDb.Execute strSQL
            
    '       Remove the records from the cart table
            DeleteAllCart
    
    '       Close the checkout and broswe form and display the main menu
            DoCmd.Close acForm, "frmCheckout", acSaveNo
            DoCmd.Close acForm, "frmBrowse", acSaveNo
            Forms!frmMainMenu.objOption.Form.Requery
            ShowForm Forms!frmMainMenu, True
            
            MsgBox "You have rented " & lngCartCnt & " Movie(s)", vbInformation, "Checkout Complete"
        End If
        
    End Sub
    BlueBox(1).zip

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,740
    Welcome to the forum.
    You might get focused responses if you post a copy of your database(zip format) with enough record to repeat the issue.

  3. #3
    RichH is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    3
    Thank You! Usually the forums I've been to don't want people linking workbooks, so this is nice. Here's a link to my Google Drive.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Post 3 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Best to attach file to post. Many will not download files from other locations.
    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.

  6. #6
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,421
    RichH, you may have attached the wrong DB. frmBrowse has no recordsource, so it's impossible to set up a checkout scenario.
    Also, it will cause an error if you try to make a form visible or invisible that is not loaded. You need the below function to verify the form's status which would go into modFunctions:
    Code:
    Public Function fcnIsLoaded(frm As String) As Boolean
        If CurrentProject.AllForms(frm).IsLoaded Then
            fcnIsLoaded = True
        Else
            fcnIsLoaded = False
        End If
    End Function
    
    Then an example of use in frmLoginCust:
    Code:
    Private Sub cmdOk_Click()
    On Error GoTo cmdOk_Click_Err
        Dim strUser     As String
    '   Call the subroutine to reset the backcolor
        ResetBackcolor
            
    '   Test to confirm required entries are present
        If EntryIsValid Then
    '       Required entries were found so initialize the variables
            strUser = Me.txtUser.Column(1)
    '       Hide the browse form in case they want to continue shopping
            If fcnIsLoaded("frmBrowse") Then
                ShowForm Forms!frmBrowse, False
            End If
    '       Open the checkout form and close the login form
            DoCmd.OpenForm "frmCheckout", , , , , , strUser
            DoCmd.Close acForm, "frmLoginCust", acSaveNo
            
        Else
    '       Missing required entry so prompt the user
            MsgBox "Please enter the required data", vbInformation, "Missing Entry"
        End If
    cmdOk_Click_Exit:
    

  7. #7
    RichH is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    3
    The first menu that kind of kicks things off is the frmMainMenu. After the user selects either to browse movies at a physical location or via the online option, frmBrowse loads. A sub form is then loaded depending on filter selection (Actor/Genre/Director). the lstBrowse listbox chooses which form to load upon selection. The List Box lst(Genre/Actor/Director, dependng on the form) has a source that is dependent on the kioskID of the kiosk selected. If they browse online, the kioskID passed is a wildcard "*".

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

Similar Threads

  1. Replies: 7
    Last Post: 05-25-2018, 05:56 PM
  2. Automatically Insert rows with Days in Months
    By NoviceAccess in forum Access
    Replies: 10
    Last Post: 08-30-2016, 06:00 PM
  3. Insert all rows to access database
    By krasi_e_d in forum Access
    Replies: 5
    Last Post: 10-10-2012, 01:42 PM
  4. insert multiple rows in access
    By learning_graccess in forum Queries
    Replies: 1
    Last Post: 03-31-2012, 10:15 AM
  5. Insert x number of rows based on value
    By opopanax666 in forum Programming
    Replies: 4
    Last Post: 10-26-2010, 03:26 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