Can't reference in VBA sub, a folder set by a file dialog function on a form...and text box value DISAPPEARS!

Peter_W

New Member
Joined
Apr 2, 2018
Messages
31
Hello all,

I have what I thought was easy, but obviously doing something wrong, as a non-programmer. I've checked the Access board here for similar issues too:

First, I am setting up a folder from a button, with a small sub and function on the button click. First issue is, the folder will correctly show in the text box, and then it later DISAPPEARS on from the text box! I have never seen a text box value cleared, without some user action or sub code.

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


My hope is, after the folder is PERMANENTLY set in the form's text box, I can then later on use it when I export a query out to Excel, per this code:

'Set the Folder path for Exporting Query to Excel

strPath = Forms![frmMainMenu]![txtForBrowser].Value


So, the sub that should export the query, cycles through okay, but the destination template file (xltm), where I'm hoping to see the exported data, is untouched and unchanged.

I've tried many different versions of the above code snips, but think the above are the closest to being good. I'm confounded...why is the folder properly populated in the form text box, and then disappears??

Thanks in advance for any response, PW
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I have been able to save the folder in the form now, through trial and error. I think I am okay for the most part now. No need for any response now, thank you.
 
Upvote 0
@Peter_W
While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered elsewhere.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top