Solved

Access 2007 SQL Data Mismatch (Integer)

Posted on 2013-01-10
11
365 Views
Last Modified: 2013-01-14
When I try to run code below, I receive a data mismatch at:

sSQL = "SELECT * FROM tblNewlyHomeless ORDER BY [Client Uid], [Test], [Entry Entry Date], [Previous Entry Exit Exit Date]"


Public Function Test()
  Dim sSQL As Integer
  DAO.DBEngine.SetOption dbMaxLocksPerFile, 1500000
  sSQL = "SELECT * FROM tblNewlyHomeless ORDER BY [Client Uid], [Test], [Entry Entry Date], [Previous Entry Exit Exit Date]"

  Dim rs As Recordset
  Set rs = CurrentDb.OpenRecordset(sSQL)
 
 
  Do Until rs.EOF
    rs.Edit
    rs("Test") = DateDiff("d", [Entry Entry Date], [Previous Entry Exit Exit Date])
    rs.Update
    rs.MoveNext

  Loop

 End Function

Not sure why, need some assistance
0
Comment
Question by:jbakestull
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38765617
First guess is that your [test] field is a string, not a number, DateDiff will return a number, so [test] must be numeric.

BTW, those are some really strange looking field names!
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38765619
What are data types for [Test], [Entry Entry Date], and [Previous Entry Exit Exit Date] in our table?
0
 

Author Comment

by:jbakestull
ID: 38765626
test is number, [Entry Entry Date] and [Previous Entry Exit Exit Date] are dates
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Norie
ID: 38765634
sSQL should be declared as String, no Integer.
0
 

Author Comment

by:jbakestull
ID: 38765638
string returns an data mismatch type, not sure how to write the SQL as an integer.
0
 

Author Comment

by:jbakestull
ID: 38765640
sorry, data mistype is at

rs("Test") = DateDiff("d", [Entry Entry Date], [Previous Entry Exit Exit Date])
0
 
LVL 34

Expert Comment

by:Norie
ID: 38765644
This returns a type mismatch?
Dim sSQL As String

  DAO.DBEngine.SetOption dbMaxLocksPerFile, 1500000

  sSQL = "SELECT * FROM tblNewlyHomeless ORDER BY [Client Uid], [Test], [Entry Entry Date], [Previous Entry Exit Exit Date]"

Open in new window


Or do you mean the error moves further down the code?
0
 

Author Comment

by:jbakestull
ID: 38765654
When sSQL is a integer the data mismatch occurs at line:

sSQL = "SELECT * FROM tblNewlyHomeless ORDER BY [Client Uid], [Test], [Entry Entry Date], [Previous Entry Exit Exit Date]"


When sSQL is a string the data mismatch occurs at line:

rs("Test") = DateDiff("d", [Entry Entry Date], [Previous Entry Exit Exit Date])
0
 
LVL 34

Accepted Solution

by:
Norie earned 500 total points
ID: 38765660
Where are [Entry Entry Date] and [Previous Entry Exit Exit Date] coming from?

Are they supposed to be from the recordset you've opened?
rs("Test") = DateDiff("d", rs("Entry Entry Date"), rs("Previous Entry Exit Exit Date")) 

Open in new window

0
 
LVL 26

Expert Comment

by:jerryb30
ID: 38765713
How are you dealing with null values in you (presumably) date fields?
Can you post a sample database, with at least table structures?
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38766520
I think imnorie got it right, you cannot just refer to the field name, you must use the recordset object and the field name.

The only other thing I can think of is that there are records where either [Entry Entry Date] or [Previous Entry Exit Exit Date] is a null value.  If that is possible, then consider something like:

rs("Test") = DateDiff("d", NZ(rs("Entry Entry Date"), #1/1/2000#), NZ(rs("Previous Entry Exit Exit Date"), Date()))
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question