open file name and save active control

  • Thread starter Thread starter Marco
  • Start date Start date
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
 
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
 
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
 
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
---------------------------
 
Something like:
Dim ctl As Control
......

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

thx
 

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

Back
Top