473,394 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Data type mismatch in criteria expression - Code Posted

When the Command Button "Notify" is clicked, I am wanting to send out an email to the user with appropriate information in the email (works great), check the "Notified" check box (does not work), and disable the "Notify" button (works).

After the email is sent off, i get a Data type mismatch in criteria expression error. I am completely stumped. Any help would be greatly appreciated! Here is my code (I removed the email portion as it is working fine)... Thanks in advance!

I am working with Access 2003

Expand|Select|Wrap|Line Numbers
  1. Private Sub Notify_Click()
  2.     On Error GoTo Err_Notify_Click
  3.  
  4.     Dim stWhere As String       '-- Criteria for DLookup
  5.     Dim varTo As Variant        '-- Address for SendObject
  6.     Dim stText As String        '-- E-mail text
  7.     Dim RecDate As Variant      '-- Rec date for e-mail text
  8.     Dim stSubject As String     '-- Subject line of e-mail
  9.     Dim stTicketID As String    '-- The ticket ID from form
  10.     Dim Method As String        '-- Method of Delivery Information
  11.     Dim stWho As String         '-- Reference to tblUsers
  12.     Dim strSQL As String        '-- Create SQL update statement
  13.     Dim errLoop As Error
  14.  
  15.     'Set the update statement to disable command button
  16.     'once e-mail is sent
  17.     strSQL = "UPDATE Requests SET Requests.Notified = -1 " & _
  18.              "Where Requests.CauseNo = " & Me.CauseNo & ";"
  19.  
  20.     Debug.Print strSQL
  21.     On Error GoTo Err_Execute
  22.     CurrentDb.Execute (strSQL)
  23.     On Error GoTo 0
  24.  
  25.     'Requery checkbox to show checked
  26.     'after update statement has ran
  27.     'and disable send mail command button
  28.     Me.Notified.Requery
  29.     Me.Notified.SetFocus
  30.     Me.Notify.Enabled = False
  31.  
  32.     Exit Sub
  33.  
  34. Err_Execute:
  35.  
  36.     ' Notify user of any errors that result from
  37.     ' executing the query.
  38.     If DBEngine.Errors.Count > 0 Then
  39.         For Each errLoop In DBEngine.Errors
  40.             MsgBox "Error number: " & errLoop.Number & vbCr & _
  41.                    errLoop.Description
  42.         Next errLoop
  43.     End If
  44.  
  45.     Resume Next
  46.  
  47. Exit_Notify_Click:
  48.     Exit Sub
  49.  
  50. Err_Notify_Click:
  51.     MsgBox Err.Description
  52.     Resume Exit_Notify_Click
  53.  
  54. End Sub
  55.  
Sep 22 '09 #1

✓ answered by NeoPa

@ChipR
If CauseNo is a text field then you probably need to change your lines #17 to #18 to :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE Requests SET [Notified]=TRUE " & _
  2.          "Where [CauseNo]='" & Me.CauseNo & "';"
PS. Good call Chip. I should have remembered to add the link too.

9 4049
ChipR
1,287 Expert 1GB
You should be able to use Notified.Refresh rather than .Requery, since you haven't added or deleted any records. Have you commented out the error handling to see on what line your error occurs?
Sep 22 '09 #2
@ChipR
When commenting out the error handling, the error occurs on line 22

CurrentDB.Execute (strSQL)
Sep 22 '09 #3
ChipR
1,287 Expert 1GB
Well, that narrows it down well. What types are the table fields for Notified and CauseNo?
Sep 22 '09 #4
@ChipR
Notified is a yes/no check box

CauseNo is a text field
Sep 22 '09 #5
ChipR
1,287 Expert 1GB
Here's a very handy reference article on
Quotes (') and Double-Quotes (") - Where and When to use them.

Short story is, since CauseNo is a text field, you need something like:
Expand|Select|Wrap|Line Numbers
  1.   ...
  2.   "Where Requests.CauseNo = '" & Me.CauseNo & "';"
Sep 22 '09 #6
NeoPa
32,556 Expert Mod 16PB
@ChipR
If CauseNo is a text field then you probably need to change your lines #17 to #18 to :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE Requests SET [Notified]=TRUE " & _
  2.          "Where [CauseNo]='" & Me.CauseNo & "';"
PS. Good call Chip. I should have remembered to add the link too.
Sep 22 '09 #7
ChipR and NeoPa,

Thanks for all the good info. On campus right now, but will be giving all this a whirl in a little bit. I'll chime back in when I get the chance to review the info in the link and try the code modifications. Thanks again.
Sep 22 '09 #8
@NeoPa
Did the trick! Thanks for the help! I guess its time to get back to relearning the small things!
Sep 22 '09 #9
NeoPa
32,556 Expert Mod 16PB
I'm very pleased to hear that we were able to help.

Welcome to Bytes!
Sep 22 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ArcadeJr | last post by:
Good morning all! I have been getting a Run-time Error message #3464 - Data Type mismatch in criteria expression. While trying to run a query. I have a database where the field Asset_Number...
3
by: martlaco1 | last post by:
Trying to fix a query that (I thought) had worked once upon a time, and I keep getting a Data Type Mismatch error whenever I enter any criteria for an expression using a Mid function. Without the...
1
by: amitbadgi | last post by:
I am getting the following error while converting an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Data type mismatch in criteria expression. ...
1
by: jmarr02s | last post by:
I am using MS Access 2003 and get the following error "Data type mismatch in criteria expression" Any suggestions on how to fix this? This is my code: SELECT IIf(=15 Or =19, "15 og 19",...
2
by: psychomad | last post by:
Please, can someone help me out to solve this error, i've been searching throughout my codes and yet i didnt succeed in finding the error!!!! The Error is: Server Error in '/' Application....
5
by: blackburnj55 | last post by:
Hi, I am constructing a website for a bike shop. I am using dreamweaver and an access database to create it. I have made a query where two criteria are entered to get results. These are :...
19
by: Lysander | last post by:
I have written a query that takes three integers representing day,month and year, forms a date from them and compares this date to the date the record was entered and returns any records where the...
1
by: Bobby Edward | last post by:
Using Access db with VS2008 (ASP.NET/VB.NET).... On the INSERT command I get this error: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression. I haven't found a...
14
by: ezechiel | last post by:
Hello, I know others have the same problem here, I tried (a lot! ) different solutions but still can't get around the problem.. :s Here's the code: Private Sub cb_swedit_sopi_AfterUpdate()...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.