Page 6 of 7 FirstFirst 1234567 LastLast
Results 76 to 90 of 104
  1. #76
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79
    But still no insert.

  2. #77
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79
    Yes it displays the correct value in the code, but it never inserts.

  3. #78
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    IIRC, the field types *must* match the incoming value types.
    InternalIncidentID, AgencyID - Me.InternalIncidentID, x
    ...do they?

  4. #79
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79
    InternalIncidentID is a text field, and AgencyID is a number field. the variable x is declared an integer and is used for the AgencyID value.

    I'm wondering if I need to stop using Me.InternalIncidentID and maybe declare a variable for it. When I changed the code to read "If x = 4" which is one of the two values x can have, I got a "Too few parameters expected error." That makes me think maybe it's something with the InternalIncidentID, but I did step through the code. This is odd.

  5. #80
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What *kind* of number "AgencyID is a number field"? Integer, Long, single, double...

  6. #81
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79
    It's an integer

  7. #82
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    If InternalIncidentID is a text field then I'm pretty sure you will need delimiters:

    ('" & Me.InternalIncidentID & "',

  8. #83
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79
    that's true, I missed that. I added them in but no change to the insert.

  9. #84
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I'll have to go get another thinking cap. Mine seems to be dry right now.

  10. #85
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79
    No problem! I'm a bit baffled myself

  11. #86
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Since your UPDATE query has no qualification (WHERE or HAVING clause) wouldn't it just update every record?

  12. #87
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79
    Possibly, but I think since x only has one value, either 4 or 5, it would only update the one record... although I'm not positive...

  13. #88
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79
    RuralGuy, I've attached another copy of the db per your request, just to make sure it is the most recent copy of this. The workable combo boxes that don't sort are on the tab title "Program" and the ones that do sort but don't write are on the tab "Page568" Thanks!
    Attached Files Attached Files

  14. #89
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    PMFJI,

    I've been looking at the code and have a few comments.
    Code:
        Dim x As Integer
        x = [Forms]![frmNewMain]![Combo573]
        MsgBox "The value of x is [" & x & "]"
        If x = True Then
            sSQL = "INSERT INTO tblAgencyIncident(InternalIncidentID, AgencyID) Values ('" & Me.InternalIncidentID & "', " & x & ")"
        Else
            sSQL = "DELETE FROM tblAgencyIncident WHERE InternalIncidentID = '" & Me.InternalIncidentID & "' AND  AgencyID = 'x'"
        End If
    Referring to the code snippet above:
    1) The RED "X" (in the "DELETE" sql statement) should be concatenated to the SQL, just like the append string.

    2) The test (in BLUE) "x = True" will ALWAYS return FALSE.
    Consider: "X" is declared Integer. But MS has defined a constant TRUE as -1. So, if x = 4 and TRUE = -1, then the test, 4 = -1, is forever FALSE. (AFAIK )


    Not that it matters , but I don't understand the reasoning behind the test " If x = True Then". The only time the code will execute is when the combo box "Combo573" (poor name, BTW) is changed. Do you really want to delete a record if you change agencies?
    I would add a check to ensure an Incident # was entered before trying to execute the SQL statements.


    My $0.02.........


    -----------------------------------------------
    In table "tblIncidents", "Description" is a reserved word and shouldn't be used as object names.
    In same table, there are spaces in field names. Shouldn't use spaces, punctuation or special characters (exception is the underscore) in object names.

  15. #90
    tbbrown32 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    79
    Thanks for the info! I will change the DELETE x to be concatenated to the SQL, I fixed the table names and desc field. As far as the code goes, I'm basically trying to get the table to update if x changes. I guess I don't need to delete the record, but will it update when only one part of the composite pk changes like that? If that's possible, then that'd be great!

Page 6 of 7 FirstFirst 1234567 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 09-03-2015, 11:12 AM
  2. Replies: 4
    Last Post: 06-18-2014, 08:31 PM
  3. Combo box to filter a combo box
    By svrich in forum Access
    Replies: 20
    Last Post: 04-13-2014, 10:36 PM
  4. Replies: 1
    Last Post: 10-01-2013, 09:25 PM
  5. Combo Box filter – help!
    By catat in forum Forms
    Replies: 1
    Last Post: 08-24-2010, 04:15 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