FollowHyperlink Method

J

Janelle.Dunlap

I have used the CreateDatabase method in vb to create a new access
database. I now need to open this new database and close the existing
one. The code I am using to do this is as follows:

Application.FollowHyperlink strSaveFileName
Application.Quit

Where strSaveFileName is the string file path to the newly created
database. When I run this I am getting an error: Cannot Open Specified
File. This doesn't make sense to me because I can open the new
database manually and have also tried adding a hyperlink on my form
that points directly to the new database - and this works fine. Any
suggestions?
 
D

Dirk Goldgar

I have used the CreateDatabase method in vb to create a new access
database. I now need to open this new database and close the existing
one. The code I am using to do this is as follows:

Application.FollowHyperlink strSaveFileName
Application.Quit

Where strSaveFileName is the string file path to the newly created
database. When I run this I am getting an error: Cannot Open
Specified File. This doesn't make sense to me because I can open the
new database manually and have also tried adding a hyperlink on my
form that points directly to the new database - and this works fine.
Any suggestions?

What exactly is in strSaveFileName? Does it include the full path to
the file?
 
J

Janelle.Dunlap

Dirk said:
What exactly is in strSaveFileName? Does it include the full path to
the file?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup

Yes, it returns the full file path to the new database. I'm sure it is
returning the right path because I have referenced it in other
situations and it is running correctly.
 
D

Dirk Goldgar

Yes, it returns the full file path to the new database. I'm sure it
is returning the right path because I have referenced it in other
situations and it is running correctly.

This code works fine for me:

Dim strSaveFileName As String

strSaveFileName = "C:\Temp\MyNewDB.mdb"

DBEngine.CreateDatabase strSaveFileName, dbLangGeneral

Application.FollowHyperlink strSaveFileName
Application.Quit

If it doesn't work for you, maybe the "mdb" filetype isn't associated
with Microsoft Access on your system, though I'd think it would be. Or
maybe you still have that database opened exclusively in your code -- is
that possible?
 
J

Janelle.Dunlap

You were right. My strSaveFileName is not being recognized as an mdb
file. The file path itself is defined by the user through the
File/Save dialog box. Here is the code I am using:

Dim strFilter As String
Dim strSaveFileName As String

strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda), *.mdb)",
_
"*MDA;*MDB")
strSaveFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=False, _
DialogTitle:="Please Enter File Name for New
Database...", _
Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)

This currently defines the string without .mdb at the end. However in
a different instance in my database I used the same FollowHyperlink
method with the following code and it worked perfectly:

strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)",
_
"*.MDA;*.MDB")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select a Database...", _
Flags:=ahtOFN_HIDEREADONLY)

I don't know why it is saving the file path differently in these two
instances.
 
J

Janelle.Dunlap

I figured it out. I just needed to define the Default Ext as mdb.
Thanks for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top