Home > Software engineering >  Consult excel 438 error object does not support this property or method error didn't know where
Consult excel 438 error object does not support this property or method error didn't know where

Time:12-07

Code like this:

The mark of which is the line error: Sheets (" Sheet1 "). Label20. Caption=Format (No, "000000")

The complete code is this:
Private Sub CommandButton1_Click ()
SaveAndPrint
End Sub


Private Function SaveAndPrint ()
Dim myObject As Object
Dim strNo strCircle, strSql As String
Dim cn As New ADODB. Connection
Dim the rs As New ADODB. You
Dim bUpdate As Boolean


Cn. The Provider="Microsoft. ACE. The OLEDB. 12.0"
Cn. Open (Application) ActiveWorkbook) Path & amp; "\ Sample accdb")

Rs. The ActiveConnection=cn

A=Format (Date, "yyyy/mm/dd", vbSunday, vbUseSystem)
B=Format (Time, "" hh: mm, vbSunday, vbUseSystem)


StrSql="select * from Data", "
Rs. Open (strSql), adOpenStatic adLockPessimistic

StrCircle="0"

If (OptionButton7. Value=https://bbs.csdn.net/topics/True) Then
StrCircle="1"
End the If
If (OptionButton8. Value=https://bbs.csdn.net/topics/True) Then
StrCircle="2"
End the If
If (OptionButton9. Value=https://bbs.csdn.net/topics/True) Then
StrCircle="3"
End the If
If (OptionButton10. Value=https://bbs.csdn.net/topics/True) Then
StrCircle="4"
End the If

'If the rs. RecordCount & gt; 0 Then
'bUpdate=True
'the Else
BUpdate=False
'End If

With Worksheets (" Sheet1 ")
If (bUpdate=True) Then
StrSql="Update Data Set Num=" & amp; "'" & amp; "000002" & amp; "'" & amp; ", "& amp; "Name=" & amp; "'" & amp; TextBox1. Text & amp; "'" & amp; ", "& amp; "Phone=" & amp; "'" & amp; TextBox4. Text & amp; "'" & amp; ", "& amp; "StartTime=" & amp; "'" & amp; TextBox2. Text & amp; ":" & amp; TextBox3. Text & amp; "'" & amp; ", "& amp; "EndTime=" & amp; "'" & amp; TextBox5. Text & amp; ":" & amp; TextBox6. Text & amp; "'" & amp; ", "& amp; "Circle=" & amp; "'" & amp; TextBox4. Text & amp; "'" & amp; ", "& amp; "The Drawer=" & amp; "'" & amp; TextBox14. Text & amp; "'" & amp; ", "& amp; "Coach=" & amp; "'" & amp; TextBox8. Text & amp; "'" & amp; ", "& amp; "DriveSchool=" & amp; "'" & amp; TextBox9. Text & amp; "'" & amp; ", "& amp; "DrawDate=" & amp; "'" & amp; TextBox12. Text & amp; "/" & amp; TextBox10. Text & amp; "/" & amp; TextBox11. Text & amp; "'
"Cn. The Execute strSql
The Else
Rs. AddNew
Rs! Num=Label20. Caption
Rs! Name=TextBox1. Text
Rs! Phone=TextBox4. Text
Rs! StartTime=TextBox2. Text & amp; ":" & amp; TextBox3. Text
Rs! EndTime=TextBox5. Text & amp; ":" & amp; TextBox6. Text
Rs! Circle=strCircle
Rs! The Drawer=TextBox14. Text
Rs! Coach=TextBox8. Text
Rs! DriveSchool=TextBox9. Text
Rs! DrawDate=TextBox12. Text & amp; "/" & amp; TextBox10. Text & amp; "/" & amp; TextBox11. Text
Rs! Money=TextBox13
Rs. Update


End the If
End With

No=No + 1
Label20. Caption=Format (No, "000000")

Rs. Close
The Set cn=Nothing
Set the rs=Nothing

With ActiveSheet. PageSetup
The PrintArea="B4: I19" '//print area
FitToPagesWide=1 '//page size is one page
FitToPagesTall=1 'high//page is one page
. PaperSize//page size=xlPaperA4 '
'Copies=3
'PrintZoomColumn=2
'PrintZoomRow=3
. '=xlLandscape' Orientation//horizontal print
End With

Sheets (" Sheet1 "). The PrintOut

TextBox1. Text=""
TextBox2. Text=""
TextBox3. Text=""
TextBox4. Text=""
TextBox5. Text=""
TextBox6. Text=""
TextBox14. Text=""
TextBox8. Text=""
TextBox9. Text=""
TextBox10. Text=""
TextBox11. Text=""
TextBox12. Text=""
TextBox13. Text=""

End the Function

Private Function statistics ()

Dim myObject As Object
Dim strTmp, strDate, strSql As String
Dim cn As New ADODB. Connection
Dim the rs As New ADODB. You
Dim bUpdate As Boolean


Cn. The Provider="Microsoft. ACE. The OLEDB. 12.0"
Cn. Open (Application) ActiveWorkbook) Path & amp; "\ Sample accdb")

Rs. The ActiveConnection=cn

StrDate=Format (Date, "yyyy/mm/dd")

StrSql="SELECT sum (Money) as Acount, count (Money) as the Amount, sum (DATEDIFF (' n ', StartTime, EndTime)) as TotalTime FROM Data where DrawDate=" & amp; "#" & amp; StrDate & amp; "#", "
Rs. Open (strSql), adOpenStatic adLockPessimistic

With Worksheets (" Sheet1 ")
Cells (40, 2)=strDate
Cells (40, 3)=rs! The Amount
Cells (40, 4)=rs! Acount
Cells (40, 5)=rs! TotalTime
End With

Rs. Close
The Set cn=Nothing
Set the rs=Nothing

End the Function


Private Sub CommandButton2_Click ()
The statistics
End Sub


To ask ah, thank you very much
  •  Tags:  
  • VBA
  • Related