Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2011
    Location
    Grand Haven / Royal Oak Michigan USA
    Posts
    23

    Red face Unanswered: An Expression You Entered Is the Wrong Data Type for one of the Arguments

    Initially I wanted to populate a form I have opened to record a new record with data from an existing record… allowing users to select via a combo box driven by a query with Record ID, Date, Supervisor ID and Employee ID. Then I thought maybe I just need to create a form that mirrors the new record form and set that to open using the Record ID. But in both instances I am receiving the error “An Expression You Entered Is the Wrong Data Type for one of the Arguments”. The Record ID is auto number long in the table. The value returned from the query for the Record ID is String. No matter how I try to do this I receive the same result:


    Private Sub cboDates_Click()
    On Error GoTo Err_datesearch_Click

    Dim lngEPDPID As Long
    'Dim intEPDPID As Integer
    'Dim strEPDPID As String
    Dim strEmpID As String
    Dim strSupID As String
    Dim strEPDPDt As String

    Stop

    strEPDPDt = Me.cboDates.Column(0)
    strEmpID = Me.cboDates.Column(1)
    strSupID = Me.cboDates.Column(2)
    lngEPDPID = Me.cboDates.Column(3)
    'intEPDPID = Me.cboDates.Column(3)
    'strEPDPID = Me.cboDates.Column(3)



    DoCmd.OpenForm Form_frmEPDP02, acNormal, , "EPDPID = " & lngEPDPID
    'DoCmd.OpenForm Form_frmEPDP02, acNormal, , "EPDPID = " & intEPDPID
    'DoCmd.OpenForm Form_frmEPDP02, acNormal, , "EPDPID = " & strEPDPID

    Me.Visible = False

    Exit_datesearch_Click:

    Exit Sub

    Err_datesearch_Click:

    MsgBox Err.Description
    Resume Exit_datesearch_Click

    End Sub

    Up The Creek

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    expressly coerce the value tot he correct datatype

    eg
    myIntColumn = clng(astringvalue)
    theres a whole raft of conversion functions cdate, cint, clng, cdbl and so on

    however you may also need to check the astringvalue is actually a number
    consider using the isnumber function
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jan 2011
    Location
    Grand Haven / Royal Oak Michigan USA
    Posts
    23
    Even when I try that I am still up the creek with the same error... what do you make of that?

    lngEPDPID = CLng(Me.cboDates.Column(3))


    ?typename(lngEPDPID)
    Long

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    which line is the error occuring on
    have you checked there is a value for the column
    are you using option explicit for each and every module
    bear in mond that the columns collection is base 0, so the third column will actually be column(2)
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Jan 2011
    Location
    Grand Haven / Royal Oak Michigan USA
    Posts
    23
    DoCmd.OpenForm Form_frmEPDP02, acNormal, , "EPDPID = " & lngEPDPID
    is where the code errors… the appropriate value seems to be all set for lngEPDPID to match up to the record desired to open. I attached a screen shot of the table to see if that might help?
    Attached Thumbnails Attached Thumbnails problem.bmp  

  6. #6
    Join Date
    Jan 2011
    Location
    Grand Haven / Royal Oak Michigan USA
    Posts
    23
    Private Sub cboDates_Click()
    On Error GoTo Err_datesearch_Click

    Dim lngEPDPID As Long
    Dim strEmpID As String
    Dim strSupID As String
    Dim strEPDPDt As String

    Stop

    strEPDPDt = Me.cboDates.Column(0)
    strEmpID = Me.cboDates.Column(1)
    strSupID = Me.cboDates.Column(2)
    lngEPDPID = CLng(Me.cboDates.Column(3))

    DoCmd.OpenForm Form_frmEPDP02, acNormal, , "EPDPID = " & lngEPDPID

    Me.Visible = False

    Exit_datesearch_Click:

    Exit Sub

    Err_datesearch_Click:

    MsgBox Err.Description
    Resume Exit_datesearch_Click

    End Sub

  7. #7
    Join Date
    Jan 2011
    Location
    Grand Haven / Royal Oak Michigan USA
    Posts
    23
    I also tried this way to no avail:

    Private Sub cboDates_Click()
    On Error GoTo Err_datesearch_Click

    Dim lngEPDPID As Long

    Stop

    lngEPDPID = CLng(Me.cboDates.Column(3))

    DoCmd.OpenForm Form_frmEPDP02, acNormal, , "EPDPID = '" & lngEPDPID & "'"

    Me.Visible = False

    Exit_datesearch_Click:

    Exit Sub

    Err_datesearch_Click:

    MsgBox Err.Description
    Resume Exit_datesearch_Click

    End Sub

  8. #8
    Join Date
    Jan 2011
    Location
    Grand Haven / Royal Oak Michigan USA
    Posts
    23

    Talking This code resolved my issue:

    Private Sub cboDates_Click()
    On Error GoTo Err_datesearch_Click

    Dim lngEPDPID As Long

    'Stop

    lngEPDPID = CLng(Me.cboDates.Column(3))

    DoCmd.OpenForm "frmEPDP02", acNormal, , "EPDPID = " & lngEPDPID, acFormEdit

    Me.Undo
    Me.Visible = False

    Exit_datesearch_Click:

    Exit Sub

    Err_datesearch_Click:

    MsgBox Err.Description
    Resume Exit_datesearch_Click

    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •