Results 1 to 6 of 6
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Confusing ODBC Error Message

    This the 3rd in a series of posts I have made regarding this data entry form which I'm hoping to distribute soon. The purpose is for medical professionals to enter diagnosis codes for a particular patient. The same patient cannot be given the same diagnosis twice. When this happens I get one of those long, confusing ODBC error messages. Example below.



    Click image for larger version. 

Name:	odbc call failed.JPG 
Views:	12 
Size:	33.1 KB 
ID:	27513

    Since this is not a coding error, I don't know how to trap it and translate it into English for the end user. Surely there's a way to code for this. Rather than groping about and jury-rigging this, I'll await your expert replies.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,523
    it says your are trying to add a key in a table that already has one. 534209
    you cant add it twice.

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,469
    In the AfterUpdate of that diagnostic field(which should be a combo box), do a DLookup of that code and Patient in the table. If it is found, give them a message saying so, SetFocus to the Diagnosis box and don't save the value.

    cboDiagCode_AfterUpdate:

    IF Not Isnull(DLookup("DiagCode", "tblPatientData", "DiagCode = '" & me.cboDiagCode & "'")) Then
    MsgBox "The Diagnostic code " & me.cboDiagCode & " you entered has already been selected for this patient."
    Me.cboDiagCode.SetFocus
    End
    End If

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I assume this is happening after the user fills out an entire form and tries to save it. In general I try to avoid errors rather than just trap for them, so I'd lean towards checking for duplicates during data entry. That way you also avoid the user filling out the whole form and then finding out it's a duplicate.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Thanks, I will address this tomorrow. Time to go home.

  6. #6
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Since it is a very small form with only two fields to fill out, I went with this.

    Code:
        P_ID = Me.Parent.P_ID.Caption
        
        strsql = "SELECT * FROM tblDiagnosis_ICD10 WHERE P_RegNo = '" & P_ID & "' and ICD10 = '" & Me.ICD10 & "' and Admit_Date = #" & Me.Parent.Admit_Date & "#"
        
        Set rst = CurrentDb.OpenRecordset(strsql)
            
        If Not rst.EOF Then
            MsgBox "Diagnosis code " & Me.ICD10 & ": " & Me.cboICD10_Description & " has already been used for this patient admission."
            rst.Close
            Set rst = Nothing
            Me.Undo
            Me.cbo_ICD10.SetFocus
            GoTo err_Exit
        End If
    Worked great. Thanks for your help.

    Paul

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

Similar Threads

  1. Confusing compile error
    By GraeagleBill in forum Programming
    Replies: 5
    Last Post: 07-24-2016, 10:06 PM
  2. Replies: 1
    Last Post: 03-02-2015, 09:44 AM
  3. Replies: 1
    Last Post: 12-16-2014, 03:48 PM
  4. Confusing runtime error 424 Object needed
    By RichardAnderson in forum Forms
    Replies: 3
    Last Post: 10-18-2013, 02:32 PM
  5. confusing datatype error issue
    By TheShabz in forum Queries
    Replies: 5
    Last Post: 10-11-2010, 05:14 PM

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