Solved

Access 2007 SQL Data Mismatch (Integer)

Posted on 2013-01-10
11
363 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 (Access MVP)
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 (Access MVP)
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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

710 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