Results 1 to 4 of 4
  1. #1
    DevilDawg is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2023
    Posts
    11

    Arrow Weird issue with an insert query

    I have a table that is set to hold temporary values. It is built as:


    Field Name :CID
    Data Type :Autonumber
    Field Size :Long Integer
    Format :blank
    Caption :blank
    Indexed :Yes(No Duplicates)


    Text Align :General
    ________________________________________________
    Field Name :OID
    Data Type :Number
    Field Size :Long Integer
    Format :blank
    Decimal Places :Auto
    Input Mask :blank
    Caption :blank
    Default Value :0
    Validation Rule :blank
    Validation Text :blank
    Required :No
    Indexed :Yes (Duplicates OK)
    Text Align :General
    ________________________________________________
    Field Name :CATID
    Data Type :Number
    Data Type :Number
    Field Size :Long Integer
    Format :blank
    Decimal Places :Auto
    Input Mask :blank
    Caption :blank
    Default Value :0
    Validation Rule :blank
    Validation Text :blank
    Required :No
    Indexed :Yes (Duplicates OK)
    Text Align :General
    ________________________________________________
    Field Name :CN
    Data Type :Short Text
    Field Size :255
    Format :blank
    Input Mask :blank
    Caption :blank
    Default Value :blank
    Validation Rule :blank
    Validation Text :blank
    Required :No
    Allow Zero Length :Yes
    Indexed :Yes (Duplicates OK)
    Unicode Compression :Yes
    IME Mode :No Control
    IME Sentence Mode :None
    Text Align :General
    ________________________________________________
    Field Name :Rating
    Data Type :Number
    Field Size :Long Integer
    Format :blank
    Decimal Places :Auto
    Input Mask :blank
    Caption :blank
    Default Value :0
    Validation Rule :blank
    Validation Text :blank
    Required :No
    Indexed :Yes (Duplicates OK)
    Text Align :General
    ________________________________________________
    Field Name :Sbol1
    Data Type :Yes/No
    Format :Yes/No
    Caption :blank
    Default Value :No
    Validation Rule :blank
    Validation Text :blank
    Indexed :No
    Text Align :General
    ________________________________________________
    Field Name :Sbol2
    Data Type :Yes/No
    Format :Yes/No
    Caption :blank
    Default Value :No
    Validation Rule :blank
    Validation Text :blank
    Indexed :No
    Text Align :General
    ________________________________________________
    Field Name :Sbol3
    Data Type :Yes/No
    Format :Yes/No
    Caption :blank
    Default Value :No
    Validation Rule :blank
    Validation Text :blank
    Indexed :No
    Text Align :General
    ________________________________________________
    Field Name :Sbol4
    Data Type :Yes/No
    Format :Yes/No
    Caption :blank
    Default Value :No
    Validation Rule :blank
    Validation Text :blank
    Indexed :No
    Text Align :General
    ________________________________________________
    Field Name :Sbol5
    Data Type :Yes/No
    Format :Yes/No
    Caption :blank
    Default Value :No
    Validation Rule :blank
    Validation Text :blank
    Indexed :No
    Text Align :General

    I have a function :
    Code:
    Public Sub AddCategoryToOrder(ByVal intOID, ByVal inCID)
      Dim varSQL As String
     On Error GoTo Err_Handler
       
      varSQL = "INSERT INTO tbltmpCategoryRatings (OID, CATID) SELECT " & intOID & ", " & inCID
    
    
      Debug.Print varSQL
    
    
      DoCmd.SetWarnings False
        DoCmd.RunSQL (varSQL)
      DoCmd.SetWarnings True
    
    
    Exit_Handler:
      Exit Sub
      
    Err_Handler:
           Select Case Err.Number
    
    
            Case Else
              MsgBox "The following error has occurred." & vbCrLf & vbCrLf & _
                     "Error Number: " & Err.Number & vbCrLf & _
                     "Error Source: modDatabaseInteraction:AddCategoryToOrder" & vbCrLf & _
                     "Error Description: " & Err.Description, _
                     vbCritical, "An Error has Occurred!"
              Call LogError(Err.Number, Err.Description, "modDatabaseInteraction:AddCategoryToOrder")
              Resume Exit_Handler
            End Select
    End Sub
    I can add the first with no issue. When I attempt to add a second by this means, I get the error that it cannot add it due to "and it didn't add 1 record(s) to the table due to key violation ". Upon additional messing, I found that even when I manually go into the table and add one, it duplicated the CID value, a value that is supposed to be auto incremented. I deleted the existing table and made another and it still does the same thing. Is this some bug (Using Access 2016). I have also compacted and repaired the database and it continues to do the same. I have never encountered this before and just wondering if I am the only one or if someone sees something I am doing incorrectly, have I lost my mind (rhetorical question; I know I have). Anyone have an insight? The values are being passed correctly too.

  2. #2
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Can you upload a copy of the database?
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  3. #3
    CarlettoFed is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    257
    You need to change the data type in the temporary table:
    Code:
    Field Name :CID
    Data Type :Number

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    I would add the datatypes to your procedure arguments.
    Use "Values" rather than "Select"
    Use the .execute method as it will roll back changes if an error is encountered.


    Code:
    Public Sub AddCategoryToOrder(ByVal intOID as Long, ByVal inCID as long)
      Dim varSQL As String
     On Error GoTo Err_Handler
       
      varSQL = "INSERT INTO tbltmpCategoryRatings (OID, CATID) Values(" & intOID & ", " & inCID &")"
    
    
      Debug.Print varSQL
    
    
    CurrentDb.Execute  varSQL, dbFailOnError
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Weird print issue arround attachment field
    By irish634 in forum Access
    Replies: 6
    Last Post: 06-13-2019, 02:32 PM
  2. Weird Query issue
    By RayMilhon in forum Queries
    Replies: 5
    Last Post: 11-07-2017, 12:40 PM
  3. Weird Sorting Issue
    By MattPGA in forum Access
    Replies: 6
    Last Post: 07-17-2017, 12:33 PM
  4. Weird Issue with forms
    By newbieaccess203 in forum Queries
    Replies: 3
    Last Post: 01-12-2016, 02:46 PM
  5. Weird Speed issue
    By devlin7 in forum Access
    Replies: 12
    Last Post: 02-09-2014, 07:32 PM

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