Hello all,
Even as a novice programmer, I thought I could get this Access VBA code to work, but can't.
I would like to set a folder's value in a form text box, for later use to direct the user's exporting to Excel. I am assuming I can set just the folder path....and that I do not need to select a specific file.
So, I have this code entered for a button's button click, to first allow the user to specify a folder. Surely I must be doing something wrong, since the folder will first correctly populate in the text box, but will disappear after the form is closed:
Public Sub cmdBrowserButton_Click()
Dim strChoice As String
strChoice = FolderSelection
If Len(strChoice) > 0 Then
Me.txtForBrowser.Value = strChoice
Else
Close
End If
End Sub
Public Function FolderSelection() As String
Dim objFD As Object
Dim strOut As String
strOut = vbNullString
'msoFileDialogFolderPicker = 4
Set objFD = Application.FileDialog(4)
If objFD.Show = -1 Then
strOut = objFD.SelectedItems(1)
End If
Set objFD = Nothing
FolderSelection = strOut
End Function
Again, after a specific folder is set by the form, I am later hoping to use the specified folder when exporting a query to Excel, per this code in another sub:
'Set the Folder path for Exporting Query to Excel
strPath = Forms![frmMainMenu]![txtForBrowser].Value
So all in all, the exporting sub does cycle through, but the expected query data does not show in the destination template (xltm) file.
I assume I'm doing something wrong in the above code. Everything else in the database I'm creating, works fine.
Any feedback would be most appreciated, thank you.
PW
Even as a novice programmer, I thought I could get this Access VBA code to work, but can't.
I would like to set a folder's value in a form text box, for later use to direct the user's exporting to Excel. I am assuming I can set just the folder path....and that I do not need to select a specific file.
So, I have this code entered for a button's button click, to first allow the user to specify a folder. Surely I must be doing something wrong, since the folder will first correctly populate in the text box, but will disappear after the form is closed:
Public Sub cmdBrowserButton_Click()
Dim strChoice As String
strChoice = FolderSelection
If Len(strChoice) > 0 Then
Me.txtForBrowser.Value = strChoice
Else
Close
End If
End Sub
Public Function FolderSelection() As String
Dim objFD As Object
Dim strOut As String
strOut = vbNullString
'msoFileDialogFolderPicker = 4
Set objFD = Application.FileDialog(4)
If objFD.Show = -1 Then
strOut = objFD.SelectedItems(1)
End If
Set objFD = Nothing
FolderSelection = strOut
End Function
Again, after a specific folder is set by the form, I am later hoping to use the specified folder when exporting a query to Excel, per this code in another sub:
'Set the Folder path for Exporting Query to Excel
strPath = Forms![frmMainMenu]![txtForBrowser].Value
So all in all, the exporting sub does cycle through, but the expected query data does not show in the destination template (xltm) file.
I assume I'm doing something wrong in the above code. Everything else in the database I'm creating, works fine.
Any feedback would be most appreciated, thank you.
PW