PC Review


Reply
Thread Tools Rate Thread

Dir statement throws a type mismatch

 
 
Hydra
Guest
Posts: n/a
 
      21st Jul 2009
If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then

or

If Not Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb") is Nothing

both throw an error that says type mismatch.

I don't see a problem with either one.


????
 
Reply With Quote
 
 
 
 
Jack Leach
Guest
Posts: n/a
 
      21st Jul 2009
With the space in the pathname you will need to enclose the path itself
inside another set of quotes. I'm not positive but think this will work:

If Len(Dir("""C:\......ion.mdb""")) > 0

hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



"Hydra" wrote:

> If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
>
> or
>
> If Not Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb") is Nothing
>
> both throw an error that says type mismatch.
>
> I don't see a problem with either one.
>
>
> ????

 
Reply With Quote
 
Hydra
Guest
Posts: n/a
 
      21st Jul 2009
Weird, because this code used to work.

"Jack Leach" wrote:

> With the space in the pathname you will need to enclose the path itself
> inside another set of quotes. I'm not positive but think this will work:
>
> If Len(Dir("""C:\......ion.mdb""")) > 0
>
> hth
> --
> Jack Leach
> www.tristatemachine.com
>
> "I haven''t failed, I''ve found ten thousand ways that don''t work."
> -Thomas Edison (1847-1931)
>
>
>
> "Hydra" wrote:
>
> > If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
> >
> > or
> >
> > If Not Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb") is Nothing
> >
> > both throw an error that says type mismatch.
> >
> > I don't see a problem with either one.
> >
> >
> > ????

 
Reply With Quote
 
Jack Leach
Guest
Posts: n/a
 
      21st Jul 2009
So... did that work with the double quotes?
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



"Hydra" wrote:

> Weird, because this code used to work.
>
> "Jack Leach" wrote:
>
> > With the space in the pathname you will need to enclose the path itself
> > inside another set of quotes. I'm not positive but think this will work:
> >
> > If Len(Dir("""C:\......ion.mdb""")) > 0
> >
> > hth
> > --
> > Jack Leach
> > www.tristatemachine.com
> >
> > "I haven''t failed, I''ve found ten thousand ways that don''t work."
> > -Thomas Edison (1847-1931)
> >
> >
> >
> > "Hydra" wrote:
> >
> > > If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
> > >
> > > or
> > >
> > > If Not Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb") is Nothing
> > >
> > > both throw an error that says type mismatch.
> > >
> > > I don't see a problem with either one.
> > >
> > >
> > > ????

 
Reply With Quote
 
Hydra
Guest
Posts: n/a
 
      21st Jul 2009
Nope, took the space out and renamed the directory, and took out the hyphen
too.
Still throws a type mismatch. also Trid it with the extra quotes and it
won't compile. Throws an error that says" expected list separator or )"

"Jack Leach" wrote:

> With the space in the pathname you will need to enclose the path itself
> inside another set of quotes. I'm not positive but think this will work:
>
> If Len(Dir("""C:\......ion.mdb""")) > 0
>
> hth
> --
> Jack Leach
> www.tristatemachine.com
>
> "I haven''t failed, I''ve found ten thousand ways that don''t work."
> -Thomas Edison (1847-1931)
>
>
>
> "Hydra" wrote:
>
> > If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
> >
> > or
> >
> > If Not Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb") is Nothing
> >
> > both throw an error that says type mismatch.
> >
> > I don't see a problem with either one.
> >
> >
> > ????

 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      21st Jul 2009
The statement
If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
works for me.

Check your library references.
Check that you don't have a function named Len or Dir that you have created in
your VBA code

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Hydra wrote:
> If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
>
> or
>
> If Not Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb") is Nothing
>
> both throw an error that says type mismatch.
>
> I don't see a problem with either one.
>
>
> ????

 
Reply With Quote
 
Hydra
Guest
Posts: n/a
 
      21st Jul 2009
visual basic for applications
MS Project 12.0 object library
OLE automation
Microsoft Office 12.0 library
Microsoft Access 11.o Object library
Microsoft Excel 11.0 Object library

I must have the "Gremlins 100+X library", too.
I frequently have code copied right out of the help screen or users group
that won;t work as advertised.


"John Spencer" wrote:

> The statement
> If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
> works for me.
>
> Check your library references.
> Check that you don't have a function named Len or Dir that you have created in
> your VBA code
>
> John Spencer
> Access MVP 2002-2005, 2007-2009
> The Hilltop Institute
> University of Maryland Baltimore County
>
> Hydra wrote:
> > If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
> >
> > or
> >
> > If Not Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb") is Nothing
> >
> > both throw an error that says type mismatch.
> >
> > I don't see a problem with either one.
> >
> >
> > ????

>

 
Reply With Quote
 
Hydra
Guest
Posts: n/a
 
      21st Jul 2009
If I just skip the if statement (since I know the ifle exists)
then

appAccess.OpenCurrentDatabase strDB

Where strDB = "C:\Cobra Conversion\MSP-CobraConversion.mdb"

Throws an error that says thte database is missing or opened exclusively by
another user, when I know it is there and not open.



"John Spencer" wrote:

> The statement
> If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
> works for me.
>
> Check your library references.
> Check that you don't have a function named Len or Dir that you have created in
> your VBA code
>
> John Spencer
> Access MVP 2002-2005, 2007-2009
> The Hilltop Institute
> University of Maryland Baltimore County
>
> Hydra wrote:
> > If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
> >
> > or
> >
> > If Not Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb") is Nothing
> >
> > both throw an error that says type mismatch.
> >
> > I don't see a problem with either one.
> >
> >
> > ????

>

 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      21st Jul 2009
Sounds like your VBA may be suffering from some corruption or confusion.

Have you tried to decompile/recompile your code?

Here is a standard sequence to try to rescue a corrupted mdb

0. Make a backup copy of the file.
00. Make a backup copy of the file.

1. Uncheck the boxes under:
Tools | Options | General | Name AutoCorrect
Explanation of why: http://allenbrowne.com/bug-03.html

2. Compact the database to get rid of this junk:
Tools | Database Utilities | Compact

3. Close Access. Make a backup copy of the file.
Decompile the database by entering something like this at the command
prompt while Access is not running. It is all one line, and includes the quotes:
"c:\Program Files\Microsoft office\office\msaccess.exe" /decompile
"c:\MyPath\MyDatabase.mdb"

4. Open Access, and compact again.

5. Open a code window.
Choose References from the Tools menu.
Uncheck any references you do not need.
For a list of the ones you typically need in your version of Access, see:
http://allenbrowne.com/ser-38.html

6. Still in the code window, choose Compile from the Debug menu.
Fix any errors, and repeat until it compiles okay.

At this point, you should have a database where the name-autocorrect errors
are gone, the indexes are repaired, inconsistencies between the text- and
compiled-versions of the code are fixed, and reference ambiguities are resolved.

If it is still a problem, the next step would be to get Access to rebuild the
database for you. Follow the steps for the first symptom in this article:
Recovering from Corruption
at:
http://allenbrowne.com/ser-47.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html Reply to group,
rather than allenbrowne at mvps dot org.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Hydra wrote:
> If I just skip the if statement (since I know the ifle exists)
> then
>
> appAccess.OpenCurrentDatabase strDB
>
> Where strDB = "C:\Cobra Conversion\MSP-CobraConversion.mdb"
>
> Throws an error that says thte database is missing or opened exclusively by
> another user, when I know it is there and not open.
>
>
>
> "John Spencer" wrote:
>
>> The statement
>> If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
>> works for me.
>>
>> Check your library references.
>> Check that you don't have a function named Len or Dir that you have created in
>> your VBA code
>>
>> John Spencer
>> Access MVP 2002-2005, 2007-2009
>> The Hilltop Institute
>> University of Maryland Baltimore County
>>
>> Hydra wrote:
>>> If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
>>>
>>> or
>>>
>>> If Not Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb") is Nothing
>>>
>>> both throw an error that says type mismatch.
>>>
>>> I don't see a problem with either one.
>>>
>>>
>>> ????

 
Reply With Quote
 
Hydra
Guest
Posts: n/a
 
      21st Jul 2009
I had a misspelled DIM statement that tried to DIM Dir to a variable, hence
the type mismatch.

But now Opencurrentdatabase cannot find the file or claims it is open
exclusively.

"John Spencer" wrote:

> The statement
> If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
> works for me.
>
> Check your library references.
> Check that you don't have a function named Len or Dir that you have created in
> your VBA code
>
> John Spencer
> Access MVP 2002-2005, 2007-2009
> The Hilltop Institute
> University of Maryland Baltimore County
>
> Hydra wrote:
> > If Len(Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb")) > 0 Then
> >
> > or
> >
> > If Not Dir("C:\Cobra Conversion\MSP-CobraConversion.mdb") is Nothing
> >
> > both throw an error that says type mismatch.
> >
> > I don't see a problem with either one.
> >
> >
> > ????

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type MisMatch with Set Statement RyanH Microsoft Excel Programming 4 5th Feb 2008 02:20 PM
[Q] Save As throws type mismatch error in control's code? Jason Weiss Microsoft Excel Misc 1 16th Jul 2005 04:21 AM
Case when statement gives type mismatch Henrik Microsoft Excel Programming 2 16th Jun 2004 04:36 PM
Type mismatch while running If statement =?Utf-8?B?U3RlbA==?= Microsoft Excel Programming 4 18th Dec 2003 09:19 AM
Type mismatch error in set statement Krisse Microsoft Access Form Coding 1 19th Jul 2003 12:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:14 PM.