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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Common Dialog control. 1

Status
Not open for further replies.

Qwert0000

Technical User
Oct 24, 2003
30
0
0
Hi,

I finally got the common dialog control to work using the code at,
I just need a little help setting the flags and checking the directory that is returned.

I am using this to set a bound text box to a file name for linking a picture within my form.

I have my filter set as (ahtAddFilterItem(strFilter, "Pictures (*.BMP)", "*.BMP")

and have the inital directory set (CurrentProject.path & "\pics").

I am uncertaine about what flags to set, if any, the example showed hide read only

I would also like to check the return result to see if it was chosen from the inital directory so I can store it as file name only if it was.


Any help on this matter would be greatly appriciated.
 
You should be able to set most of the properties (such as filter etc through the nice properties page which comes with the common dialog control (double click on it to open it). You will probably need to set the initial directory in code, but that is not too hard.

I created a form with a common dialog control & a command button. The common dialog was called CommonDialog0 (default name, lazy me!), & the command button was Command3 (again, lazy me!). I also added a textbox control, named txtPath.

In the command buttons click event I added the following code which does what you need; it returns the full path if the file is not located in the same dir as the currentproject.path & strSubDir

Private Sub Command3_Click()
Dim strTemp As String, strPath As String, strSubDir As String
Dim pos As Integer

'Define the subdir path here e.g. "\pics\"
strSubDir = ""

Me.CommonDialog0.FileName = ""
Me.CommonDialog0.InitDir = CurrentProject.Path & strSubDir
Me.CommonDialog0.ShowOpen
strPath = Me.CommonDialog0.FileName

pos = InStr(strPath, CurrentProject.Path & strSubDir)
If pos > 0 Then
strTemp = Right(strPath, (Len(strPath) - Len(CurrentProject.Path & strSubDir) - 1))
Else
strTemp = strPath
End If

'Now assign the completed path to the control
Me.txtPath = strTemp

End Sub


James Goodman MCSE, MCDBA
 
Thank you so much.

I had to change the strTemp = Right(strPath, (Len(strPath) - Len(CurrentProject.Path & strSubDir) - 1)) to a - 0 as the first letter of my file name was getting cut off for some reason.

I guess my original description wasn't clear because although I said I was using the common dialog control I was actually using an API module that has been referenced many times on this site to call the open file box.

I tried to make the common dialog control work but was not able to figure it out. Thanks to your help I have the common dialog control working now, and the programing seems more straight forward to me.

Is there a down side to using the common dialog control vice the API. I originally was using the filedialog command but found out that did not work on A2K. It worked great on my A2k2 machine though. Mainly using this db on an A2K machine although I will occasionally sending this db home which has A2k2.

Once again, thanks for taking time to teach a newb, the information on this site has been invaluable.

Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top