Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 30th, 2009, 08:19 AM
Registered User
 
Join Date: Jul 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Data mismatch driving me crazy

I am assigning a value to a variable from a Dlookup, I have used this before with no problems until now, it keeps returning the error of data mismatch but I can't see one anywhere:

CPName is a text field
CarPark is the table
CPCounter is a number field

This should return the string value of CPName from CarPark where the CPCounter matched 1

Code:
Dim n As Integer
Dim Temp As String
n=1
Temp = Nz(DLookup("[CPName]", "CarPark", "[CPCounter] = '" & n & "' "), 0)
It keeps giving the data mismatch error message but I can't see where the problem is, please help if you can!
 
Old July 30th, 2009, 05:38 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Quote:
CPCounter is a number field
So then WHY are you trying to compare it to a *string*????

Try
Code:
Temp = Nz(DLookup("[CPName]", "CarPark", "[CPCounter] = " & n ), 0)
Do *NOT* put apostrophes around values that SHOULD be treated as numbers.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Access Pie Chart driving me crazy kuznickic Access 6 January 14th, 2009 02:48 AM
Data Mismatch Error arholly SQL Server ASP 1 March 18th, 2008 02:34 AM
Data type mismatch sharon5469 ASP.NET 1.0 and 1.1 Basics 2 May 27th, 2007 10:01 AM
data type mismatch karma SQL Language 3 April 6th, 2006 07:58 AM
session.use_trans_sid is driving me crazy!! Snib Pro PHP 6 July 24th, 2004 04:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.