|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Option Explicit
- Public StrSN As String
-
-
- 'Callback for customUI.onLoad
- Sub rxIRibbonUI_onLoad(ribbon As IRibbonUI)
- End Sub
- 'Callback for ID_TODAY getLabel
- Sub GETTODAY(control As IRibbonControl, ByRef returnedVal)
- returnedVal = " " & Format(Now, "yyyy-m-d")
- End Sub
- 'Callback for ID_USER getLabel
- Sub GETUSER(control As IRibbonControl, ByRef returnedVal)
- Dim UserName As String
- If InStr(1, Application.UserName, "[") = 0 Then
- UserName = Application.UserName
- Else
- UserName = Left(Application.UserName, InStr(1, Application.UserName, "[") - 1)
- End If
- returnedVal = UserName
- End Sub
- 'Callback for BTN002 onAction
- Sub SendMailToChuan(control As IRibbonControl)
- Dim objOutlook As New Outlook.Application
- Dim objMail As MailItem
-
- Set objOutlook = New Outlook.Application
- Set objMail = objOutlook.CreateItem(olMailItem)
-
- objMail.To = "chuan.wang@emerson.com"
- objMail.Subject = "WQ FCV DVC auto tiering tools issue"
- objMail.Save
- objMail.Display
- Set objMail = Nothing
- Set objOutlook = Nothing
- End Sub
- 'Callback for ID_SN onChange
- Sub Input_SN(control As IRibbonControl, text As String)
- StrSN = text
- Search_SN_Data
- End Sub
- 'Callback for ID_SN getText
- Sub Reset_SN(control As IRibbonControl, ByRef returnedVal)
- End Sub
- 'Callback for Button_SN onAction
- Sub Search_SN(control As IRibbonControl)
- Search_SN_Data
- End Sub
- Public Sub Search_SN_Data()
- Dim i As Integer
- Dim strSQL As String
- ' If StrSN = "" Or StrSN = ture Then Exit Sub
-
- Cells.Clear
-
- Cells(1, 1) = "Protocol"
- Cells(2, 1) = "Level"
- Cells(3, 1) = "SerialNumber"
- Cells(4, 1) = "Valve Serial Number"
- Cells(5, 1) = "Database Tag"
- Cells(6, 1) = "Device Tag"
- Cells(7, 1) = "Descriptor"
- Cells(8, 1) = "RepOderNumber"
- Cells(9, 1) = "DVCoptions"
-
- Cells(1, 2).Select
-
- On Error GoTo errorhandle
- Cells(3, 2) = StrSN
-
- Application.ScreenUpdating = False
- ConnectDB
-
- '=============Protocol==================
- ' Dim Protocol As String
- '
- ' strSQL = "select * from openquery (betsy," & _
- ' "'SELECT COUNT(*)" & _
- ' " FROM apps.XXOM_VLVS_SERIALIZATION XVS" & _
- ' " JOIN apps.oe_order_lines_all OOL" & _
- ' " ON OOL.TOP_MODEL_LINE_ID = xvs.SALES_ORDER_LINE_ID " & _
- ' " AND OOL.ORG_ID=10606 " & _
- ' " AND OOL.ORDERED_ITEM IN (''DVC6200X1-9M1'') " & _
- ' "WHERE XVS.serial_number = ''" & StrSN & "''')"
- '
- ' If rs.State = adStateOpen Then rs.Close
- ' rs.Open strSQL, cn, adOpenKeyset, adLockOptimistic
- ' If rs(0) > 0 Then Protocol = "HART 5"
- '
- ' strSQL = "select * from openquery (betsy," & _
- ' "'SELECT COUNT(*)" & _
- ' " FROM apps.XXOM_VLVS_SERIALIZATION XVS" & _
- ' " JOIN apps.oe_order_lines_all OOL" & _
- ' " ON OOL.TOP_MODEL_LINE_ID = xvs.SALES_ORDER_LINE_ID " & _
- ' " AND OOL.ORG_ID=10606 " & _
- ' " AND OOL.ORDERED_ITEM IN (''DVC6200X1-9M2'') " & _
- ' "WHERE XVS.serial_number = ''" & StrSN & "''')"
- '
- ' If rs.State = adStateOpen Then rs.Close
- ' rs.Open strSQL, cn, adOpenKeyset, adLockOptimistic
- ' If rs(0) > 0 Then Protocol = "HART 7"
-
- ' Cells(1, 2) = Protocol
-
- '=============Level==================
-
- strSQL = "select * from openquery (betsy," & _
- "'SELECT OOL.ORDERED_ITEM " & _
- " FROM apps.XXOM_VLVS_SERIALIZATION XVS" & _
- " JOIN apps.oe_order_lines_all OOL" & _
- " ON OOL.TOP_MODEL_LINE_ID = xvs.SALES_ORDER_LINE_ID " & _
- " AND OOL.ORG_ID=10606 " & _
- " AND OOL.ORDERED_ITEM IN (''DVC6200X1-9M1''," & _
- "''DVC6200X1-9M2''," & _
- "''DVC6200X1-9D1''," & _
- "''DVC6200X1-9D2''," & _
- "''DVC6200X1-9D3''," & _
- "''DVC6200X1-9D4''," & _
- "''DVC6200X1-9D5''," & _
- "''DVC2000X1-9A1''," & _
- "''DVC2000X1-9A2''," & _
- "''DVC2000X1-9A3''," & _
- "''DVC2000X1-9A4''," & _
- "''DVC6200X1-9S1''," & _
- "''DVC6200X1-9S2''," & _
- "''DVC6200X1-9S3''," & _
- "''DVC6200X1-9S4''," & _
- "''DVC6200X1-9Q1'') " & _
- "WHERE XVS.serial_number = ''" & StrSN & "''')"
- If rs.State = adStateOpen Then rs.Close
- rs.Open strSQL, cn, adOpenKeyset, adLockOptimistic
- rs.MoveFirst
-
- Do While rs.EOF = False
- Select Case rs(0)
- '=============Protocol==================
- Case "DVC6200X1-9M1"
- Cells(1, 2) = "HART 5"
- Case "DVC6200X1-9M2"
- Cells(1, 2) = "HART 7"
- '=============Level==================
- Case "DVC6200X1-9D1"
- Cells(2, 2) = "AC"
- Case "DVC6200X1-9D2"
- Cells(2, 2) = "HC"
- Case "DVC6200X1-9D3"
- Cells(2, 2) = "AD"
- Case "DVC6200X1-9D4"
- Cells(2, 2) = "PD"
- Case "DVC6200X1-9D5"
- Cells(2, 2) = "OVD"
- Case "DVC6200X1-9A1"
- Cells(2, 2) = "AC"
- Case "DVC6200X1-9A2"
- Cells(2, 2) = "HC"
- Case "DVC6200X1-9A3"
- Cells(2, 2) = "AD"
- Case "DVC6200X1-9A4"
- Cells(2, 2) = "PD"
- '=============DVCoptions==================
- Case "DVC6200X1-9S1"
- Cells(9, 2) = "DVC6200X1-9S1"
- Case "DVC6200X1-9S2"
- Cells(9, 2) = "DVC6200X1-9S2"
- Case "DVC6200X1-9S3"
- Cells(9, 2) = "DVC6200X1-9S3"
- Case "DVC6200X1-9S4"
- Cells(9, 2) = "DVC6200X1-9S4"
- Case "DVC6200X1-9Q1"
- If Cells(9, 2) = "" Then
- Cells(9, 2) = "DVC6200X1-9Q1"
- End If
- End Select
-
- rs.MoveNext
- Loop
-
- ' Cells(2, 2) = Level
- '=============DVCoptions==================
- ' Dim strDVCOptions As String
- '
- ' strSQL = "select * from openquery (betsy," & _
- ' "'SELECT OOL.ORDERED_ITEM" & _
- ' " FROM apps.XXOM_VLVS_SERIALIZATION XVS" & _
- ' " JOIN apps.oe_order_lines_all OOL" & _
- ' " ON OOL.TOP_MODEL_LINE_ID = xvs.SALES_ORDER_LINE_ID " & _
- ' " AND OOL.ORG_ID=10606 " & _
- ' " AND OOL.ORDERED_ITEM IN (''DVC6200X1-9S1''," & _
- ' "''DVC6200X1-9S2''," & _
- ' "''DVC6200X1-9S3''," & _
- ' "''DVC6200X1-9S4'') " & _
- ' "WHERE XVS.serial_number = ''" & StrSN & "''')"
- '
- ' If rs.State = adStateOpen Then rs.Close
- ' rs.Open strSQL, cn, adOpenKeyset, adLockOptimistic
- '
- ' If rs.RecordCount > 0 Then
- ' strDVCOptions = rs(0)
- ' Else
- ' strSQL = "select * from openquery (betsy," & _
- ' "'SELECT COUNT(*)" & _
- ' " FROM apps.XXOM_VLVS_SERIALIZATION XVS" & _
- ' " JOIN apps.oe_order_lines_all OOL" & _
- ' " ON OOL.TOP_MODEL_LINE_ID = xvs.SALES_ORDER_LINE_ID " & _
- ' " AND OOL.ORG_ID=10606 " & _
- ' " AND OOL.ORDERED_ITEM IN (''DVC6200X1-9Q1'') " & _
- ' "WHERE XVS.serial_number = ''" & StrSN & "''')"
- '
- ' If rs.State = adStateOpen Then rs.Close
- ' rs.Open strSQL, cn, adOpenKeyset, adLockOptimistic
- ' If rs(0) > 0 Then strDVCOptions = "DVC6200X1-9Q1"
- ' End If
- '
- '
- ' Cells(9, 2) = strDVCOptions
-
-
-
- Cells.EntireColumn.AutoFit
-
- DisconnectDB
- Application.ScreenUpdating = True
- Exit Sub
-
- errorhandle:
- If Err.Description <> "Object variable or With block variable not set" Then
- MsgBox "Sorry, we encounter an issue. no data extracted" & vbCrLf & vbCrLf & "Please contact with Chuan Wang." & vbCrLf & vbCrLf & Err.Description, vbCritical + vbOKOnly, "WQ FCV MES @ Feb 2021"
- End If
- DisconnectDB
- Application.ScreenUpdating = True
-
-
- End Sub
复制代码 |
|