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!

A question from Thread702-840722 - how to provide the windows drives 1

Status
Not open for further replies.

cfvcf

Technical User
Nov 8, 2007
77
US
I was reading Thread702-840722, (now closed) and TheAceMan1 gave a suggestion for providing the common windows dialog for locations and file types that is below. I have a form that someone can add a photo from a text box. They can either manually enter the drive etc, but I'd like to give them the ... feature to pick the file themselves. How would one go about doing that? I did what TheAceMan1 said "go to the MenuBar click Insert ActiveX Control, but I don't have that option. I'm using Access 2003. Any ideas?

From thread and TheAceMan1:
Step 4
I decided to make it easy for you to enter your picture Path & FileNames by incorperating the Common Dialog Control (don't ask . . . just keep going!). Wether or not this can be done depends on your version of Access.

So on the MenuBar click Insert - ActiveX Control... A dialog opens. Scroll down thru the list. Your looking for: Microsoft Common Dialog Control, version 6. If you don't find it, you'll have to enter your Path & FileNames manually (in this case goto Quote 5).

If do have it, select it and click OK. A small square button will appear on the form. Just leave it, its hidden in form view.

In the Other Properties Tab for the new control, set the Name Property at the top:
Name = axCom

Now . . . . in the DoubleClick Event for the picPath control, add the following code:
Dim axCtl As Object

Set axCtl = Me!axCom

axCtl.DialogTitle = "Insert Picture Path & FileName"
axCtl.InitDir = "D:\Graphics\Misc"
axCtl.Filter = "Bitmaps (*.bmp)|*.bmp|Jpegs (*.jpg)|*.jpg|Gifs (*.gif)|*.gif"
axCtl.ShowOpen
Me!Text3 = axCtl.FileName

Set axCtl = Nothing

Compile & Save and close the form
 
How are ya cfvcf . . .

You can use the API [blue]GetFinenameFromBrowse[/blue] instead.

See my post here; thread702-1289131

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Wow, thanks for all that code, but I am confused.
I'm assuming the Me!TextboxName is the text box that could either already have a file name shown, but then it would also give them the ability to select another file to replace what is there?
What is "variable"?
And when would you code these two statements?

Me!TextboxName = BrowseFiles()
variable = BrowseFiles()

Thanks!
 
I'm using Access 2003
So, why not simply use the FileDialog object ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
cfvcf . . .

The two lines:
Code:
[blue]   Me!TextboxName = BrowseFiles()
   variable = BrowseFiles()[/blue]
are just examples of using the [blue]BrowseFiles[/blue] function in code. [blue]Me!TextboxName[/blue] you've already figured out. [blue]variable[/blue] is a string variable declared in code (you have a routine that needs the path):
Code:
[blue] Dim MyPath as String

   MyPath = BrowseFiles()
   [green]'
   ' the rest of the routine
   '[/green][/blue]
cfvcf said:
[blue]And when would you code these two statements?[/blue]
You of course would make use of the [blue]Me!TextboxName[/blue] assignment line. The question is how you intend to make the browser available to the user? I typically use an [blue]Image Object[/blue] with a graphic of a folder, right along side the textbox. The object is sized just small enough to see the folder. In the click event of the object I have:
Code:
[blue]   Dim rtnPath As String

   rtnPath = BrowseFiles()
   If rtnPath <> "" Then Me!MyTextboxName = rtnPath[/blue]
You could do the same with a [blue]command button[/blue]. As an alternative, you could put the code in the [blue]Double Click[/blue] event of the textbox, with a tooltip that saids: [blue]Click here to select file![/blue].

[blue]PHV[/blue] recommends using the [blue]FileDialog[/blue] object. I've used it at work and its good, I'm just reluctant to offer what I can't personally test at home (A2K here). Besides we don't know if you have 2K3. In any case, the API works across the board (don't know about A2K7 yet).

BTW: default starting folder and file filtering can be preset!

[blue]Your Thoughts? . . .[/blue]


Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
I thank you both for your input, I just simply have to run out for now. I'll work on this in the am.

I want to try them both, I'm thinking that AceMan's way would be good to know for other versions. I do have 2003, where do I find the FileDialog object?

Thanks again to you both!
 
AceMan - you are the 1!
Just too easy when you copy other work! Now I'm still not up there with you.....just how do you preset the folder location? And default to "All Files *.*" ?
 
how do you preset the folder location?
here:
StrPtr("c:\"), _

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I've looked up StrPtr and realize it is a string pointer, but I'm not sure how I would use it in the following code:

Private Sub btn_PhotoLoc_Click()
Dim rtnPath As String
rtnPath = BrowseFiles() 'Code I got from TheAceMan1
If rtnPath <> "" Then
Me!PhotoImagePath = rtnPath
Me![PictureImage].Picture = Me![PhotoImagePath]
End If
End Sub

Thanks!
 
cfvcf . . .

The changes are made in the [blue]BrowseFiles[/blue] function. See [purple]purple text[/purple] below:
Code:
[blue]Public Function BrowseFiles()
   Dim sSave As String
   
   sSave = Space(255)
   'If we're on WinNT, call the unicode version of the function
   If IsWinNT Then
      GetFileNameFromBrowseW Screen.ActiveForm.hwnd, _
                             StrPtr(sSave), _
                             255, _
                             StrPtr("[purple][b]C:\Corel\Photos[/b][/purple]"), _
                             StrPtr("txt"), _
                             StrPtr("[purple][b]Bitmap files[/b][/purple] (*.[purple][b]bmp[/b][/purple])" + Chr$(0) + "*.[purple][b]bmp[/b][/purple]" + Chr$(0) + _
                                    "All files (*.*)" + Chr$(0) + "*.*" + Chr$(0)), _
                              StrPtr("The Title")
   'If we're not on WinNT, call the ANSI version of the function
   Else
      GetFileNameFromBrowseA Screen.ActiveForm.hwnd, _
                             sSave, _
                             255, _
                             "c:\", _
                             "txt", _
                             "All files (*.*)" + Chr$(0) + "*.*" + Chr$(0) + _
                             "Text files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0), _
                             "The Title"
   End If
   
   BrowseFiles = Trim(Replace(sSave, Chr$(0), " "))

End Function[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thanks everything works great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top