Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening specific file using common dialog

Status
Not open for further replies.

azkabancells

Instructor
May 8, 2005
4
GB
How do I open a specific file (an access db) using the common dialog function? I presume it needs to be automatically displayed in the file name of the open file box.

Also I want to be able to either open it at the beginning of the file or create new record by opening at the end of the file. I have created a menu with new and open for this purpose but can't find the code I need.

Thanks for looking
 
c is the CommonDialog

Code:
c.FileName = ""
c.ShowOpen

If c.FileName <> "" Then
  MsgBox c.FileName
End If

If you select a file AND press OK in "c.FileName" there will be the full path of the selected file (containing "\the_file"). Now you can open it:

1. Using Shell() method (there will be error if you write Shell(c.Filename), because .mdb is not .exe !)
2. Having added a reference to MS Access type object library, open access (visible or not) and then open the specific database.


-bclt
 
Shell("c:\program files\office ...\access.exe" & " " & c.FileName, 1)

In the "..." I input the path where access.exe is, then a space and then the filename.

The "1" is for access; the window to be focused and also to have its normal size. (equivalent = vbNormalFocus)


-bclt



 
Thanks. I specifically need to open a db file called address. On Private Sub mnuNew_Click()I need to open it to eof and on Private Sub mnuOpen_Click()I need to open to bof.

I have so far

f = FreeFile
CMDialog1.Filter = "all files|*.*|text|*.txt"
CMDialog1.FilterIndex = 0
CMDialog1.FileName = "C:\Address"
CMDialog1.ShowOpen
MsgBox "You selected: " + CMDialog1.FileName
TextFileNum = FreeFile
OpenFileName = CMDialog1.FileName
Open OpenFileName For Output As #f

Also are there any good tutorial sites on common dialog and linking db's to access via code (not data control).

Thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top