Home > Software engineering >  VB Access data table export to Excel, were 2007
VB Access data table export to Excel, were 2007

Time:10-02

Private Sub cmdout_Click ()

Dim RST As New ADODB. You
RST. Open the "select" & amp; Left (Trim (Text1. Text), Len (Trim (Text1. Text)) - 1) & amp; "From" & amp; Combo1. Text & amp; "", cn1 adOpenDynamic, adLockOptimistic

Dim xlsApp As Excel. Application 'definition of Excel program
Dim xlsBook As Excel. The Workbook 'definition work thin
Dim xlsSheet As Excel. The Worksheet 'definition Worksheet
Dim I, j As Long
The Set xlsApp=CreateObject (" Excel. Application ")
'create Excel application
The Set xlsBook=xlsApp. Workbooks. Add 'create work thin
Set xlsSheet=xlsBook. Worksheets (1) 'create work table
On the Error Resume Next
J=1
EOF
Do Until RST.For I=1 To RST. Fields. The Count
XlsSheet. Cells (j, I)=RST. Fields (I - 1)
'written record set (not including header)
Next I
RST. MoveNext
J=j + 1
Loop
XlsApp. Visible=True 'shows the spreadsheet
XlsBook. SaveAs App. Path & amp; "\ export data. XLSX"
The Set xlsApp=Nothing 'exchange control to Excel
RST. Close
Cn1. Close
The Set of RST=Nothing
The Set cn1=Nothing
Unload Me
Unload FM

End Sub

Private Sub combo1_Click () 'to the list box add table field name
Dim As Integer I
Dim the SRS As New ADODB. You
List1. Clear
The SRS. Open combo1. Text, cn1, adOpenKeyset, adLockOptimistic
I=SRS. Fields. The Count
For I=0 To SRS. Fields. The Count - 1
List1. AddItem SRS. Fields (I). The Name
Next I
The SRS. Close
Set the SRS=Nothing

End Sub

Private Sub img1_Click () 'select files to add records to the combo box

Dim rs1 As New ADODB. You
Cmd00. Filter="Access files (*. Accdb) | *. Accdb | all files (*. *) | *. *", "
Cmd00. CancelError=True
Cmd00. DialogTitle="open Access file"
Cmd00. ShowOpen
Fn=cmd00. FileName
Text1.=cmd00 FileName

If fn="" Then
MsgBox "please choose to Access the file again!" , vbInformation + vbOKOnly
End the If
If cn1. State=adStateOpen Then
Cn1. Close
Combo1. Clear
End the If
Call accdbcon
The Set rs1=cn1. OpenSchema (adSchemaTables)
EOF
Do Until rs1.If Left (rs1! Table_name, 4) & lt;> "MSys" Then "filtering system file name
Combo1. AddItem rs1! Table_name
End the If
Rs1. MoveNext
Loop
Rs1. Close
The Set of rs1=Nothing
End Sub

Private Sub list1_ItemCheck (Item As an Integer)

Text1. Text=Text1. Text & amp; List1. List (Item) & amp; ", "
'the list1 is assigned to the selected field in text1 text box
Cmdout. Enabled=True

End Sub




1, want to export the entire table rather than a field in a table
2, the error is how to solve the debug statements that
RST. Open the "select" & amp; Left (Trim (Text1. Text), Len (Trim (Text1. Text)) - 1) & amp; "From" & amp; Combo1. Text & amp; "", cn1 adOpenDynamic, adLockOptimistic

CodePudding user response:

 Debug. Print "select" & amp; Left (Trim (Text1. Text), Len (Trim (Text1. Text)) - 1) & amp; "From" & amp; Combo1. Text & amp; "" 

What content?

CodePudding user response:

reference 1st floor Tiger_Zhao response:
 Debug. Print "select" & amp; Left (Trim (Text1. Text), Len (Trim (Text1. Text)) - 1) & amp; "From" & amp; Combo1. Text & amp; "" 

What content?

Thank you for this problem has been solved the program still haven't finished late will have a problem and then turn to you

CodePudding user response:

reference 1st floor Tiger_Zhao response:
 Debug. Print "select" & amp; Left (Trim (Text1. Text), Len (Trim (Text1. Text)) - 1) & amp; "From" & amp; Combo1. Text & amp; "" 

What content?


The following code is to achieve the function of the query, but the form open pop-up adodc1 prompt box said at least one parameter is not set value
Private Sub Cmd_Yes_Click ()
If Combo_gcmc. Text="" Then
MsgBox "please select a project name
"End the If
If Combo_sjxx. Text=Protocol Then
FrmProtocol. Show 0, Me
ElseIf Combo_sjxx. Text=Strokedata Then
FrmStrokedata. Show 0, Me
ElseIf Combo_sjxx. Text=pile driving records Then
Frm pile driving records. The Show 0, the Me
ElseIf Combo_sjxx. Text=engineering pile information Then
Information Frm engineering piles. Show 0, the Me
ElseIf Combo_sjxx. Text=the axial bearing capacity design parameters Then
Frm the axial bearing capacity of design parameters. The Show 0, the Me
The Else
MsgBox "please select data options
"End the If
End Sub

Private Sub RefreshData ()
'set the data source
Adodc1. The ConnectionString=conn
Adodc1. RecordSource="SELECT PF_name from construction number"
Adodc1. Refresh
End Sub

Private Sub Cmd_Back_Click ()
Unload Me
End Sub

Private Sub Form_Load ()
'Dim conn As New ADODB. Connection
'set the record source
Adodc1. The ConnectionString=conn
Adodc1. RecordSource="SELECT * FROM construction number where PF_name order by Project_ID"
Adodc1. Refresh
End Sub

Whether the conn, please not be defined, and Dim conn As New ADODB. Connection will solve the problem?

CodePudding user response:

reference 1st floor Tiger_Zhao response:
 Debug. Print "select" & amp; Left (Trim (Text1. Text), Len (Trim (Text1. Text)) - 1) & amp; "From" & amp; Combo1. Text & amp; "" 

What content?


Conn in standard module has been defined as a string for global variables and the error is what reason?nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related