- ©«¤l
- 2035
- ¥DÃD
- 24
- ºëµØ
- 0
- ¿n¤À
- 2031
- ÂI¦W
- 0
- §@·~¨t²Î
- Win7
- ³nÅ骩¥»
- Office2010
- ¾\ŪÅv
- 100
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2012-3-22
- ³Ì«áµn¿ý
- 2024-2-1
|
¦^´_ 4# c_c_lai - ' [Sheet1 (¾÷²¼§@·~)]
- Option Explicit
- Option Base 1
- Dim cnn As Object ' New ADODB.Connection
- Dim cmd As Object ' New ADODB.Command
- Dim rs As Object ' New ADODB.Recordset
- Dim strSQL As String
- Dim editMode As Boolean
- Dim State, CursorLocation
- Sub OpenDB()
- If ExcelData.Value = True Then ' [data$]
- Set cnn = CreateObject("ADODB.Connection")
- Set rs = CreateObject("ADODB.Recordset")
- Set cmd = CreateObject("ADODB.Command")
- Else ' ¾÷²¼¬ö¿ý
- Set cnn = New ADODB.Connection
- Set rs = New ADODB.Recordset
- Set cmd = New ADODB.Command
- End If
- ' ObjectStateEnum Values
- ' Returns a value describing if the connection is open or closed
- ' Specifies whether an object is open or closed, connecting to a data source,
- ' executing a command, or retrieving data.
- ' --------------------------------------------------------------------------
- ' Constant Value Description
- ' --------------------------------------------------------------------------
- ' adStateClosed 0 The object is closed
- ' adStateOpen 1 The object is open
- ' adStateConnecting 2 The object is connecting
- ' adStateExecuting 4 The object is executing a command
- ' adStateFetching 8 The rows of the object are being retrieved
- With cnn
- If .State = 1 Then .Close ' adStateOpen
-
- If ExcelData.Value = True Then
- .ConnectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & _
- ActiveWorkbook.Path & Application.PathSeparator & ActiveWorkbook.Name
- Else
- .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & _
- ThisWorkbook.Path & Application.PathSeparator & "¾÷²¼°O¿ý©ú²Óªí.mdb" & ";"
- ' For Microsoft.ACE.OLEDB.12.0,you need Microsoft Office 12.0 Access Database Engine to be installed.
- ' .ConnectionString = "Provider=Microsoft.Ace.OLEDB.12.0;" & "Data Source=" & _
- ' ThisWorkbook.Path & Application.PathSeparator & "¾÷²¼°O¿ý©ú²ÓªíÀÉ®×.accdb" & ";"
- End If
- .Open
- End With
- End Sub
- Sub closeRS()
- With rs
- If ExcelData.Value = False Then
- If .State = 1 Then .Close ' adStateOpen
- ' The CursorLocation property is used to set or return the location of the cursor.
- ' This property can be set to one of the CursorLocationEnum constants listed in the following table.
- ' Enumeratio0n Value Description
- ' adUseNone 1 This value indicates no cursor location.
- ' This value is not supported by the MicrosoftR OLE DB Provider for AS/400 and VSAM.
- ' adUseServer 2 This value indicates that the data provider or driver-supplied cursor is used.
- ' adUseClient 3 This value indicates that a client-side cursor supplied by a local cursor library
- ' is to be used.
- ' adUseClientBatch 3 For backward compatibility, this value indicates that a client-side cursor supplied by
- ' a local cursor library is to be used.
- .CursorLocation = 3 ' adUseClient
- Else
- If State = 1 Then .Close ' adStateOpen
- CursorLocation = 3 ' adUseClient
- End If
- End With
- End Sub
- Private Sub ExcelData_Click()
- ' MsgBox "Option is Excel Data "
- End Sub
- Private Sub SQLData_Click()
- ' MsgBox "Option is SQL Data "
- End Sub
- Private Sub UpdateDropDowns()
- If ExcelData.Value = True Then
- strSQL = "Select Distinct [ñÃÒ¤º®e] From [ñÃÒ¶µ¥Ø$] Order by [ñÃÒ¤º®e]"
- Else
- strSQL = "Select Distinct ñÃÒ¤º®e From ñÃÒ¶µ¥Ø Order by ñÃÒ¤º®e"
- End If
-
- ' closeRS
- OpenDB
- License1.Clear
- License2.Clear
-
- rs.Open strSQL, cnn, 1, 3 ' adOpenKeyset, adLockOptimistic
- If rs.RecordCount > 0 Then
- Do While Not rs.EOF
- License1.AddItem rs.Fields(0) ' Select Distinct [ñÃÒ¤º®e] From
- License2.AddItem rs.Fields(0) ' Select Distinct [ñÃÒ¤º®e] From
- rs.MoveNext
- Loop
- Else
- MsgBox "I was not able to find any unique ñÃÒ¤º®e.", vbCritical + vbOKOnly
- Exit Sub
- End If
- End Sub
- Private Sub Confirm_Click()
- Dim tblName As String, fld As String
- Dim nCode As Range
-
- If CallID.Text = "" Then RecordExisted.Caption = "": Exit Sub
-
- RecordExisted.Caption = ""
- DateTime.Value = ""
- DataCear
- DateTime.Enabled = True
-
- UpdateDropDowns
-
- If ExcelData.Value = False And SQLData.Value = False Then ExcelData.Value = True
-
- If ExcelData.Value = True Then ' ±q Sheets("data") ¤¤Â^¨ú¸ê®Æ
- tblName = "[data$]"
- fld = "[¦W¦r]"
- Set nCode = Sheets("data").[B:B].Find(CallID.Text, , , 1)
- If Not nCode Is Nothing Then
- editMode = True
- RecordExisted.ForeColor = &HFF0000
- RecordExisted.Caption = "§ó·s¥Ø«e¸ê®Æ"
- DeleteData.Visible = True
-
- With nCode
- DeptNo.Text = .Offset(, -1)
- DateTime.Text = .Offset(, 1)
- CreditDate.Text = .Offset(, 2)
- routinefrom.Text = .Offset(, 3)
- routineto.Text = .Offset(, 4)
- contents.Text = .Offset(, 5)
- cabin.Text = .Offset(, 6)
- License1.Text = .Offset(, 7)
- LicenseFee1.Text = .Offset(, 8)
- License2.Text = .Offset(, 9)
- LicenseFee2.Text = .Offset(, 10)
- ticketfee.Text = .Offset(, 11)
- totalfee.Text = .Offset(, 12)
- remarks.Text = .Offset(, 13)
- End With
- Else
- editMode = False
- RecordExisted.ForeColor = 255
- RecordExisted.Caption = "·s¼W¤@µ§¸ê®Æ"
- DeleteData.Visible = False
- ' DateTime.Enabled = True
- DateTime.Text = Now()
- End If
- Else ' ±q Access ¾÷²¼¬ö¿ý ¤¤Â^¨ú¸ê®Æ
- tblName = "¾÷²¼¬ö¿ý"
- fld = "¦W¦r"
-
- ' Populate data
- strSQL = "SELECT * FROM " & tblName & " WHERE " & fld & " = '" & CallID.Text & "'"
-
- ' Now extract data
- closeRS
- OpenDB
-
- rs.Open strSQL, cnn, 1, 3 ' adOpenKeyset, adLockOptimistic
- ' rs.Open strSQL, cnn, adOpenDynamic, adLockOptimistic
- ' rs.Open strSQL, cnn, , adOpenDynamic
-
- If rs.RecordCount > 0 Then
- editMode = True
- RecordExisted.ForeColor = &HFF0000
- RecordExisted.Caption = "§ó·s¥Ø«e¸ê®Æ"
- DeleteData.Visible = True
-
- ' ±N·j´M¨ì°¦¸ê®Æ¼g¤J¦U¬ÛÃöÄæ¦ì¤º (0 To rs.Fields.Count - 1)
- With rs
- DeptNo.Value = .Fields(0).Value
- DateTime.Value = .Fields(2).Value
- CreditDate.Value = .Fields(3).Value
- routinefrom.Value = .Fields(4).Value
- routineto.Value = .Fields(5).Value
- contents.Value = .Fields(6).Value
- cabin.Value = .Fields(7).Value
- License1.Value = .Fields(8).Value
- LicenseFee1.Value = .Fields(9).Value
- License2.Value = .Fields(10).Value
- LicenseFee2.Value = .Fields(11).Value
- ticketfee.Value = .Fields(12).Value
- totalfee.Value = .Fields(13).Value
- remarks.Value = .Fields(14).Value
- End With
- Else
- editMode = False
- RecordExisted.ForeColor = 255
- RecordExisted.Caption = "·s¼W¤@µ§¸ê®Æ"
- DeleteData.Visible = False
- ' DateTime.Enabled = True
- DateTime.Text = Now()
- End If
- End If
- Confirm.Enabled = False
- SaveData.Enabled = True
- ResetData.Enabled = True
- DateTime.Enabled = False
- End Sub
½Æ»s¥N½X |
|