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

Pass Variable to Form Text Box in VB

Status
Not open for further replies.

lakers8176

IS-IT--Management
Apr 17, 2003
8
US
I have a variable defined in my vb code and I would like to pass that variable to a text box on a form. I'm not sure how to go about doing that. Here is the code that I am currently using. I would like to pass the varFile.

Code:
Function PickFile()

Dim fDialog As Office.FileDialog
Dim varFile As Variant
 
'Set up the File Dialog
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
  .AllowMultiSelect = False
  .Title = "Select a Text File to Import"
  .InitialFileName = "\\cvsftp001\ftproot\mis\bis111a\bis111a*.txt"
  
  'Clear out any Filters, then Add you own (1)
  .Filters.Add "Text Files", "*.TXT"
  
  'Show the Dialog. If the Show Method returns True, the User picked
  'at least 1 File, otherwise the User clicked Cancel
  If .Show Then
    For Each varFile In .SelectedItems
      'There will be only 1 File selected, so place the proper Arguments into the TransferText Method
      DoCmd.TransferText acImportFixed, "Bis111a", "Bis111a", varFile
Next
  Else      'Nothing selected in File Dialog
  End If
End With
End Function
 
How is PickFile called ?
You may add the following line before the Next instruction:
PickFile = varFile

And then in the form calling the function:
Me![your textbox].Value = PickFile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The PickFile function is called from a macro.
 
As you asked in forum705 I gave you a VBA answer.
you may try here forum181 if you insist on a macro solution.
Sorry, I don't know access macro.


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I don't insist on a macro solution. I am stating that, currently, this function is called by a macro. Does it matter how the function is called? The function PickFile works exactly how I want it to. I would just like the varFile variable to be passed a text box within my PickFile function. I'll try what you first posted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top