Solved

Select query for DBF table in Excel VBA throwing Type mismatch

Posted on 2011-02-22
4
1,384 Views
Last Modified: 2013-11-24
Hi,

the below code is failing on the last line, it is throwing a type mismatch error between the MaintCause field and the 'Disaster' value.
MaintCause is a 50 character field so it shouldn't have a problem with comparing strings.
May it have something to do with the query needing to built special for a DBF?

Any help greatly appreciated!
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + root_directory + module_prefix + "\LINES\MAINT\; Extended Properties=DBASE III;"

c1SQL = "Select * from LnMt.dbf Where Maintcause = 'Disaster'"
rs.Open c1SQL, cn, , , adCmdText

Open in new window

0
Comment
Question by:AssetFX
  • 2
4 Comments
 
LVL 41

Expert Comment

by:pcelba
ID: 34950404
It should not report such error.

You may try VFP OLE DB provider: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=e1a87d8f-2d58-491f-a0fa-95a3289c5fd4

Connection string: "Provider=vfpoledb;Data Source=d:\MyDataDirectory\;"

http://www.connectionstrings.com/visual-foxpro

and post more details about the errors.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 34956867
Can you try the  select statement directly in Access to see if you get the same error?
0
 

Accepted Solution

by:
AssetFX earned 0 total points
ID: 34957799
Hi guys, sorry for the delay, in Brisbane and internet is not very stable at the moment.

Feel silly but I just tried recreating the table and it started to work, the table is created as a linked table to a application to MapInfo and I believe it may have been corrupt.

Thanks for advice though
0
 

Author Closing Comment

by:AssetFX
ID: 34990898
Be careful with MapInfo linked attribute tables
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 7 Share with concurrent edits(Excel) 3 31
Excel Copy Macro down foe each row 4 18
Excel Automation VBA 19 25
Excel macro runs twice 13 46
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

930 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now