open file name and save active control

M

Marco

I wish to select a control in a form, to open file dialog with a button and
to save the path in that control, is this possible ?

thx
 
G

Graham R Seach

Marco,

Yes, you can. See http://www.pacificdb.com.au/MVP/Code/GetFileName.htm

But you should use a command button to implement this function. That's the
"standard" way of doing it.

Private Sub cmdFindFile_Click()
Dim lFlags As Long
Dim sPath As String

lFlags = gfnNOCHANGEDIR + gfnFILEMUSTEXIST + _
gfnEXPLORER + gfnLONGNAMES

sPath = GetFileName("", lFlags, "Select file", Me.hWnd, _
"c:\", gfnMSACCESS, , "*.mdb")
if Len(sPath) > 0 Then
Me!txtMyPath = sPath
End If
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
M

Marco

Thank you, i found some function in iternet for getfilename, but my problem
is:
save the path in select control or control with focus in a form.
I desire use "generic control name"(control with focus) so i can't type
Me!txtMyPath
 
G

Graham R Seach

Screen.ActiveControl

But the problem is that as soon as you click a button, the button has the
focus, so you will need:
Screen.PreviousControl

But you need to make sure the control can accept text, and that it can
accept it in the right way. For example, Textboxes accept text through their
Value property, whereas Labels use the Caption property. Similarly,
Listboxes (under certain circumstances can accept text input throught their
RowSource property, but only if their RowSourceType property = "Value
List" - even then, you might have to append it using a semicolon (;). Other
controls might throw an error.

You can use the ControlType property of many controls, to determine what
kind of control they are.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------
 
M

Marco

Something like:
Dim ctl As Control
......

If Len(sPath) > 0 Then
Set ctl = Screen.PreviousControl
ctl.Value = sPath
End If

thx
 
G

Graham R Seach

Marco,

....or just:
If Len(sPath) > 0 Then
Screen.PreviousControl.Value = sPath
End If

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------
 
Top