Results 1 to 10 of 10
  1. #1
    timmy is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    62

    Question Data Type Mismatch

    Hello again everyone, sorry for posting yet another question but i really need a second set of eyes here...

    The following code is designed to send an email when a button is pressed, then disable the button and tick the checkbox.

    Im getting an error "Data type mismatch in criteria expression." Access is more than helpful as usual with its error messages and only allows me to press ok or press the red "x" .

    Code:
    Private Sub emailbutton_Click()
    On Error GoTo Err_emailbutton_Click
    Dim stWhere As String 
    Dim varTo As Variant 
    Dim stText As String 
    Dim RecDate As Variant 
    Dim stSubject As String 
    Dim stTicketID As String 
    Dim stWho As String 
    Dim strHelpDesk As String 
    Dim strSQL As String 
    Dim errLoop As Error
     
    stWho = Me.EmployeeID
    stWhere = "Employees.EmployeeID = " & "'" & stWho & "'"
     
    varTo = DLookup("[Email]", "Employees", stWhere)
    stSubject = ":: Workorder Confirmation from  ::"
    stTicketID = Format(Me.WorkorderID, "9999")
    RecDate = Me.DateReceived
     
    strHelpDesk = Me.EmployeeID.Column(1)
     
    stText = "Your Workorder has been processed." & Chr$(13) & _
    Chr$(13) & "Reference Number: " & stTicketID & Chr$(13) & _
    "Processed by: " & strHelpDesk & _
    Chr$(13) & "Received Date: " & RecDate & Chr$(13) & _
    Chr$(13) & "This is an automated message." & _
    " Please do not reply to this e-mail."
     
    DoCmd.SendObject , , acFormatTXT, varTo, , , stSubject, stText, -1
     
    strSQL = "UPDATE Workorders " & _
    "SET Workorders.emailbutton = -1 " & _
    "Where Workorders.WorkorderID = " & Me.WorkorderID & ";"
     
    On Error GoTo Err_Execute
    CurrentDb.Execute strSQL, dbFailOnError
    On Error GoTo 0
     
     
    Me.emailcheck.Requery
    Me.emailcheck.SetFocus
    Me.emailbutton.Enabled = False
    Exit Sub
    Err_Execute:
     
    If DBEngine.Errors.Count > 0 Then
    For Each errLoop In DBEngine.Errors
    MsgBox "Error number: " & errLoop.Number & vbCr & _
    errLoop.Description
    Next errLoop
    End If
    Resume Next
     
    strSQL = "UPDATE Workorders " & _
    "SET Workorders.emailbutton = -1 " & _
    "Where Workorders.WorkorderID = " & Me.WorkorderID & ";"
     
    Exit_emailbutton_Click:
    Exit Sub
    Err_emailbutton_Click:
    MsgBox Err.Description
    Resume Exit_emailbutton_Click
    End Sub
    Now something i thought might affect it was that i connect to a MySQL server through linked tables, the checkbox "emailcheck" has its datasource set to a bloon field (tinyint(1)) in MySQL. I haven't written any additional code to tell access what to do with the data from MySQL, could this be causing a problem? I sort of guessed access would know what to do, naively.



    I know its a big read but any help would be appreciated, this is the biggest task ive attempted with VBA and i would be so chuffed if i got this working!
    Last edited by timmy; 04-11-2011 at 03:49 AM.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    go your OPTIONS in the vba editor:

    Code:
    tools>options>general tab>
    and check the BREAK ON ALL ERRORS radio button.

    I think that highlights the error and stop on it. Not 100% sure though.

    check that first.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can temporarily comment out the

    On Error GoTo ...

    lines and run the code. Then you should be offered a Debug button, which will take you to the offending line.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    timmy is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    62
    thanks for your replies .

    the culprit is line 17:

    varTo = DLookup("[Email]", "Employees", stWhere)

    the email field is just a varchar(50), any ideas whats wrong?

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    I don't know if you can use a variable in the 3rd arg of a dlookup, bud.

    but if you can, it needs to be changed anyway. try:


    Code:
    stWhere = "[EmployeeID] = " & stWho
    if you were going to enter the info into that arg with an actual number value instead of a variable, it would have to look like that

  6. #6
    timmy is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    62
    that solved that problem, thanks!

    Getting a 2501 error "The SendObject action was cancelled" now... nothings ever simple aye? It's on line 31 this time :

    DoCmd.SendObject , , acFormatTXT, varTo, , , stSubject, stText, -1

    most likely a problem with my args again...

  7. #7
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    that error is more complicated. might have to look at a file to figure that one out

  8. #8
    timmy is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    62
    ok, ill upload a data-less version of my DB tomorrow. Thanks so much for your help, really hope i get this problem sorted too .

  9. #9
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by timmy View Post
    ok, ill upload a data-less version of my DB tomorrow. Thanks so much for your help, really hope i get this problem sorted too .
    include step by step instructions sir, otherwise I will not look at it.

    It's courtesy, that's all. thanks

  10. #10
    timmy is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    62
    just rechecked the VBA, i think i lent on the keyboard at some point... thanks so much for your help. looks like its working!

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

Similar Threads

  1. Data type mismatch error on all of my queries!
    By MarkGLyons in forum Queries
    Replies: 3
    Last Post: 12-27-2010, 01:27 PM
  2. Data type mismatch in criteria expression
    By Douglasrac in forum Forms
    Replies: 3
    Last Post: 11-23-2010, 10:46 AM
  3. Data type mismatch in query
    By thart21 in forum Queries
    Replies: 8
    Last Post: 10-01-2010, 01:40 PM
  4. Data type mismatch in criteria expression
    By shexe in forum Queries
    Replies: 2
    Last Post: 09-01-2010, 12:47 PM
  5. data type mismatch
    By jgelpi16 in forum Programming
    Replies: 5
    Last Post: 08-02-2010, 04:15 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