Please help, im new to this VBA stuff so am stuck.
Im trying to export the data from a query to a textfile using Docmd.TransferText. The difficult part is rather than specify the query name and file name in the code, I wish to do the following:
- Allow the user to enter the query name and file names in textboxes in a Access form and then pass these names as parameters to the code (the idea of the form is to enable the user to enter the query name and destination file and based on what name is entered, the data is transfered to a text file)
-The above is only executed dependant on what is selected from a combobox. For instance, if the user selects a certain item from the combobox, the two textboxes are enabled, the user enters the query name and destination file path, clicks run and the magic happens!
Here is what I have so far:
Its in a bit of a mess so can someone help me sort it out?
Much Appreciated!
Im trying to export the data from a query to a textfile using Docmd.TransferText. The difficult part is rather than specify the query name and file name in the code, I wish to do the following:
- Allow the user to enter the query name and file names in textboxes in a Access form and then pass these names as parameters to the code (the idea of the form is to enable the user to enter the query name and destination file and based on what name is entered, the data is transfered to a text file)
-The above is only executed dependant on what is selected from a combobox. For instance, if the user selects a certain item from the combobox, the two textboxes are enabled, the user enters the query name and destination file path, clicks run and the magic happens!
Here is what I have so far:
Code:
Private Sub txtRun_DblClick(Cancel As Integer)
If comboActions.ListIndex = 0 Then
DoCmd.RunMacro "1 USAGE - Import and update data"
ElseIf comboActions.ListIndex = 2 Then
DoCmd.RunMacro "3 SUBSCRIBERS - Import and update data"
ElseIf comboActions.ListIndex = 4 Then
DoCmd.RunMacro "5 SERVICE_CHARGE - Import and update data"
ElseIf comboActions.ListIndex = 5 Then
txtQueryName.Enabled = True
TestMethod (strQry, strFile)
End If
End Sub
Public Sub TestMethod(strQry, strFile As String)
strQry = txtQueryName.Text
strFile = txtFileName.Text
DoCmd.TransferText acExportDelim, "SERV_Export_Spec", strQry, strFile, No
End Sub
Its in a bit of a mess so can someone help me sort it out?
Much Appreciated!