Hi Nelson,
If I haven't misunderstood the issue, you have to resort to VBA code to
retrieve what you are after: export data from table/query to a file based
on the fields name you selected.
I created a sample for your reference.
1. Open NorthWind.mdb
2. Create a new form, add three checkboxes to the form, add one command
button.
3. since it is a sample, I create 3 checkboxes based on three fields on the
table, you can add more checkboxes based on your table. The checkboxes'
name and its corresponding table filed/column
Checkcity: City filed/column in table employees
Checkfirstname: firtname filed/column in table employees
Checklastname: LastName filed/column in table employees
4. Copy and paste the code below to button click event.
Note: remember to add reference to ADOX library and ADO library.
Option Compare Database
Option Explicit
Private Sub Command4_Click()
Dim cat As New ADOX.Catalog
Dim cmd As ADODB.Command
Dim mview As ADOX.View
Dim myvalue As String
Dim myquery As String
Set cat = New ADOX.Catalog
Set cmd = New ADODB.Command
cat.ActiveConnection = CurrentProject.Connection
'Checkfirstname, Checklastname
If Checklastname Then 'checklastname is selected
myvalue = " LastName,"
End If
If Checkfirstname Then
myvalue = myvalue & " firstname,"
End If
If checkcity Then
myvalue = myvalue & " city,"
End If
If myvalue = "" Then
MsgBox "No field is selected!"
Exit Sub
End If
myvalue = Left(myvalue, Len(myvalue) - 1)
myquery = "select" & myvalue & " from Employees"
'basequery is the query that generates data for report.
Set mview = cat.Views("basequery")
Set cmd = mview.Command
cmd.CommandText = myquery
Set mview.Command = cmd
DoCmd.OutputTo acOutputQuery, "basequery", acFormatTXT, "c:\employees.txt"
Set mview = Nothing
Set cmd = Nothing
Set cat = Nothing
End Sub
Private Sub Form_Load()
'set all checkboxes default value to false(unchecked status)
checkcity = False
Checkfirstname = False
Checklastname = False
End Sub
Please feel free to reply to the threads if you have any concerns or
questions.
Sincerely,
Alick Ye, MCSD
Product Support Services
Microsoft Corporation
Get Secure! - <
www.microsoft.com/security>
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Nelson" <g>
| References: <
[email protected]>
| X-Tomcat-NG: microsoft.public.access.queries
|
| thx for your suggestion, but i would like to make the following form base
on
| the query:
|
| a dynamic check box display the field of the table, when user check the
| field, it will export the data of those selected fields.
| Like this:
|
| Data export:
|
| O First name
| O Last name
| O Joindate
|
| cmdExport button
|
| regards,
| Nelson
|
| "Nelson" <g> ¦b¶l¥ó ¤¤¼¶¼g...
| > i have a table contain 15 fields, how can write a sql to query those
| field
| > name?
| >
| >
| > Thx a lot
| >
| > nelson
| >
| >
|
|
|