open a Access database with VBA
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
open a Access database with VBA

 
Post new topic   Reply to topic    CADForums.net Forum Index -> MicroStation
Author Message
Alexander Heide
Guest





Posted: Tue May 18, 2004 9:38 pm    Post subject: open a Access database with VBA Reply with quote

Hi Group!

If i run following code i receive message

"Error '53'"
"File not found"

But file "House3.mdb" is there. What is wrong?

My code:

Sub OpenDatabaseFile()
Dim strFile as String
Dim strDataPath as String
Dim strdefault As String
Dim RetVal

strDataPath = Application.ActiveDesignFile.Path
strdefault = InStrRev(strDataPath, "Projects")
If strdefault > 0 Then
strDataPath = Left$(strDataPath, strdefault - 1)& "Data\House3.mdb"
End If

strFile = "strDataPath"
RetVal = Shell(strFile, 1)
End Sub



Thank You!
Alexander

Back to top
AHA
Guest





Posted: Tue May 18, 2004 10:53 pm    Post subject: Re: open a Access database with VBA Reply with quote

Just an idea. Print the contents of the resulting filename ("strDataPath") to
screen, so you can verify it is pointing to where you think it should be.

Alex

"Alexander Heide" <AHeide@yandex.ru> schreef in bericht
news:29fbeeec.0405180938.7ef4e4f3@posting.google.com...
| Hi Group!
|
| If i run following code i receive message
|
| "Error '53'"
| "File not found"
|
| But file "House3.mdb" is there. What is wrong?
|
| My code:
|
| Sub OpenDatabaseFile()
| Dim strFile as String
| Dim strDataPath as String
| Dim strdefault As String
| Dim RetVal
|
| strDataPath = Application.ActiveDesignFile.Path
| strdefault = InStrRev(strDataPath, "Projects")
| If strdefault > 0 Then
| strDataPath = Left$(strDataPath, strdefault - 1)&
"Data\House3.mdb"
| End If
|
| strFile = "strDataPath"
| RetVal = Shell(strFile, 1)
| End Sub
|
|
|
| Thank You!
| Alexander
Back to top
Jon Summers
Guest





Posted: Wed May 19, 2004 7:44 am    Post subject: Re: open a Access database with VBA Reply with quote

Alexander ...

Quote:
strDataPath = Application.ActiveDesignFile.Path
strdefault = InStrRev(strDataPath, "Projects")
If strdefault > 0 Then
strDataPath = Left$(strDataPath, strdefault - 1) & "Data\House3.mdb"
End If

strFile = "strDataPath"
RetVal = Shell(strFile, 1)

1 The Shell() function attempt to run an executable
2 A .mdb file is a data file

You can't execute a data file. VBA does not perform magic: it can't run a
data file. If you want to understand the limits of Shell(), open a
command window and enter the line you want to execute. In this case:
C:\Program Files\Bentley\Program\MicroStation\Data\House3.mdb

Back to top
Alexander Heide
Guest





Posted: Wed May 19, 2004 12:57 pm    Post subject: Re: open a Access database with VBA Reply with quote

Hi "AHA"!

Thanks for answer!

Debug.Print delivers the right path!!!
That is so curiouse!
And the file is also in the right folder.

Greetings
AHeide

"AHA" <alexWANTSNOSPAMhaerens@hotmail.com> wrote in message news:<c8dlps$94e$1@reader13.wxs.nl>...
Quote:
Just an idea. Print the contents of the resulting filename ("strDataPath") to
screen, so you can verify it is pointing to where you think it should be.

Alex

"Alexander Heide" <AHeide@yandex.ru> schreef in bericht
news:29fbeeec.0405180938.7ef4e4f3@posting.google.com...
| Hi Group!
|
| If i run following code i receive message
|
| "Error '53'"
| "File not found"
|
| But file "House3.mdb" is there. What is wrong?
|
| My code:
|
| Sub OpenDatabaseFile()
| Dim strFile as String
| Dim strDataPath as String
| Dim strdefault As String
| Dim RetVal
|
| strDataPath = Application.ActiveDesignFile.Path
| strdefault = InStrRev(strDataPath, "Projects")
| If strdefault > 0 Then
| strDataPath = Left$(strDataPath, strdefault - 1)&
"Data\House3.mdb"
| End If
|
| strFile = "strDataPath"
| RetVal = Shell(strFile, 1)
| End Sub
|
|
|
| Thank You!
| Alexander
Back to top
GeoffH
Guest





Posted: Thu May 20, 2004 9:47 am    Post subject: Re: open a Access database with VBA Reply with quote

"Jon Summers" <j.summers-no@spam-computer.org> wrote in
news:opr78k3utpav4ic8@news.btconnect.com:

Quote:
Alexander ...

strDataPath = Application.ActiveDesignFile.Path
strdefault = InStrRev(strDataPath, "Projects")
If strdefault > 0 Then
strDataPath = Left$(strDataPath, strdefault - 1) &
"Data\House3.mdb"
End If

strFile = "strDataPath"
RetVal = Shell(strFile, 1)

1 The Shell() function attempt to run an executable
2 A .mdb file is a data file

You can't execute a data file. VBA does not perform magic: it can't
run a data file. If you want to understand the limits of Shell(),
open a command window and enter the line you want to execute. In
this case: C:\Program
Files\Bentley\Program\MicroStation\Data\House3.mdb

However, if there is an association between an MDB file and MS Access, the
above command you suggest *should* start up MS Access and open the
House3.mdb database, as desired.

GeoffH
Back to top
Tim Arheit
Guest





Posted: Thu May 20, 2004 8:44 pm    Post subject: Re: open a Access database with VBA Reply with quote

On Thu, 20 May 2004 05:47:36 GMT, GeoffH <hksys@c_o_m_c_a_s_t.net>
wrote:

Quote:
"Jon Summers" <j.summers-no@spam-computer.org> wrote in
news:opr78k3utpav4ic8@news.btconnect.com:

Alexander ...

strDataPath = Application.ActiveDesignFile.Path
strdefault = InStrRev(strDataPath, "Projects")
If strdefault > 0 Then
strDataPath = Left$(strDataPath, strdefault - 1) &
"Data\House3.mdb"
End If

strFile = "strDataPath"
RetVal = Shell(strFile, 1)

1 The Shell() function attempt to run an executable
2 A .mdb file is a data file

You can't execute a data file. VBA does not perform magic: it can't
run a data file. If you want to understand the limits of Shell(),
open a command window and enter the line you want to execute. In
this case: C:\Program
Files\Bentley\Program\MicroStation\Data\House3.mdb

However, if there is an association between an MDB file and MS Access, the
above command you suggest *should* start up MS Access and open the
House3.mdb database, as desired.


Yes and no. Shell() ignores any associations. Your options are to
either use the ShellExecute API (which does use associations) or to
use the command line. ie.

RetVal = Shell("cmd /c " & strFile,1)

or (under windows 95/98):
RetVal = Shell("command /c " & strFile,1)


-Tim
Back to top
GeoffH
Guest





Posted: Fri May 21, 2004 8:27 pm    Post subject: Re: open a Access database with VBA Reply with quote

tarheit@wcoil.com (Tim Arheit) wrote in news:c8in8i$1pj$0@65.17.150.25:

Quote:
On Thu, 20 May 2004 05:47:36 GMT, GeoffH <hksys@c_o_m_c_a_s_t.net
wrote:

"Jon Summers" <j.summers-no@spam-computer.org> wrote in
news:opr78k3utpav4ic8@news.btconnect.com:

Alexander ...

strDataPath = Application.ActiveDesignFile.Path
strdefault = InStrRev(strDataPath, "Projects")
If strdefault > 0 Then
strDataPath = Left$(strDataPath, strdefault - 1) &
"Data\House3.mdb"
End If

strFile = "strDataPath"
RetVal = Shell(strFile, 1)

1 The Shell() function attempt to run an executable
2 A .mdb file is a data file

You can't execute a data file. VBA does not perform magic: it can't
run a data file. If you want to understand the limits of Shell(),
open a command window and enter the line you want to execute. In
this case: C:\Program
Files\Bentley\Program\MicroStation\Data\House3.mdb

However, if there is an association between an MDB file and MS Access,
the above command you suggest *should* start up MS Access and open the
House3.mdb database, as desired.


Yes and no. Shell() ignores any associations. Your options are to
either use the ShellExecute API (which does use associations) or to
use the command line. ie.

I was referring to the "open a command window" Jon was suggesting, because
it *will* start up MS Access.

GeoffH
http://home.comcast.net/~hksys/

Quote:

RetVal = Shell("cmd /c " & strFile,1)

or (under windows 95/98):
RetVal = Shell("command /c " & strFile,1)


-Tim
Back to top
Jon Summers
Guest





Posted: Sun May 23, 2004 10:26 am    Post subject: Re: open a Access database with VBA Reply with quote

Geoff ...

Quote:
If you want to understand the limits of Shell(),
I was referring to the "open a command window" Jon was suggesting,
because it *will* start up MS Access.

Yes, it was a bad example because the Windows Explorer file association
will perform the magic. I was hoping to illustrate the difference between
running an executable and attempting to run a data file. Next time, I'll
be more careful 8-(
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> MicroStation All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Contact Us
Powered by phpBB