Advertisement
KySoto

Monster Visual Macro

Sep 10th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim c 'As ADODB.Connection
  2. Dim com 'As ADODB.Command
  3. dim com2
  4. Dim rs 'As ADODB.Recordset
  5. dim rs2
  6. dim rs3
  7. 'Parameters that will be reused
  8. 'Queries in one place
  9. dim qry
  10. dim qry2
  11. dim qry3
  12.  
  13. If not(GOOD_QTY = 0 and BAD_QTY = 0) Then
  14.     qry = "SELECT DISTINCT TOP 1 SEQUENCE_NO FROM OPERATION WHERE (WORKORDER_BASE_ID = ?) AND (WORKORDER_LOT_ID = ?)  AND (WORKORDER_SPLIT_ID = ?) AND (WORKORDER_SUB_ID = ?) and(SEQUENCE_NO < ?)  ORDER BY SEQUENCE_NO DESC"
  15.     qry2 = "SELECT case when quantity is null then 0 else quantity end  AS Good_QTY FROM (SELECT WORKORDER_BASE_ID, WORKORDER_LOT_ID, WORKORDER_SPLIT_ID, WORKORDER_SUB_ID, OPERATION_SEQ_NO, SUM(GOOD_QTY) AS Quantity FROM LABOR_TICKET where workorder_type = 'W' GROUP BY  WORKORDER_BASE_ID, WORKORDER_LOT_ID, WORKORDER_SPLIT_ID, WORKORDER_SUB_ID, OPERATION_SEQ_NO) as a WHERE (WORKORDER_BASE_ID = ?) AND (WORKORDER_LOT_ID = ?) AND (WORKORDER_SPLIT_ID = ?) AND (WORKORDER_SUB_ID = ?) AND (OPERATION_SEQ_NO = ?)"
  16.     qry3 = "Select Desired_qty from Work_Order where Base_ID = ?"
  17.  
  18.     Set c = CreateObject("ADODB.Connection")
  19.     c.ConnectionString = "Provider=SQLOLEDB;Server=DB3;Database=VMFG1;Integrated Security = SSPI"
  20.     Set com = CreateObject("adodb.command")
  21.     com.CommandType = 1 'adCmdText
  22.     c.Open
  23.     Set com.ActiveConnection = c
  24.     com.CommandText = qry
  25.  
  26.     com.Parameters.Append  com.CreateParameter("wo", 200,1, 25,WORKORDER_BASE_ID) '("@wo,adVarChar,adParamInput,25,WORKORDER_BASE_ID)
  27.     com.Parameters.Append  com.CreateParameter("lot", 200,1, 25,WORKORDER_LOT_ID) '("@lot,adVarChar,adParamInput,25,WORKORDER_LOT_ID)
  28.     com.Parameters.Append  com.CreateParameter("split", 200,1, 25,WORKORDER_SPLIT_ID) '("@split,adVarChar,adParamInput,25,WORKORDER_SPLIT_ID)
  29.     com.Parameters.Append  com.CreateParameter("sub", 200,1, 25,WORKORDER_SUB_ID) '("@sub,adVarChar,adParamInput,25,WORKORDER_SUB_ID)
  30.     com.Parameters.Append  com.CreateParameter("op", 3, 1,,OPERATION_SEQ_NO) '("@op,adInteger,adParamInput,OPERATION_SEQ_NO)
  31.     set rs = com.Execute
  32.     'com.commandtext = qry3
  33.     'set rs3 = com.execute
  34.     if  rs.recordcount > 0 then
  35.         com.parameters(4).value = rs(OPERATION_SEQ_NO)
  36.         com.commandtext = qry2
  37.         set rs2 = com.execute
  38.         if rs2.recordcount > 0 then
  39.             if rs3.recordcount > 0 then
  40.                 if rs2("good_qty") < good_qty + bad_qty + rs3("good_qty") + rs3("BAD_QTY") then
  41.                     macro_success = false
  42.                     macro_message = "The quantity good (" & good_qty & ") + the quantity bad (" & bad_qty & ") + already clocked in quantity good (" & rs3("good_qty") & ") + already clocked in quantity bad (" & rs3("bad_qty") & ") Totaled(" & (good_qty + bad_qty + rs3("good_qty") + rs3("BAD_QTY")) & ") are greater than the previous Operation (" & rs2("good_qty") & ")"
  43.                 else
  44.                     macro_success = true
  45.                 end if
  46.             else
  47.                 if rs2("good_qty") < good_qty + bad_qty then
  48.                     macro_success = false
  49.                     macro_message = "The quantity good (" & good_qty & ") + the quantity bad (" & bad_qty & ") Totaled(" & (good_qty + bad_qty) & ") are greater than the previous Operation (" & rs2("good_qty") & ")"
  50.                 else
  51.                     macro_success = true
  52.                 end if
  53.             end if 
  54.         else
  55.             macro_success = false
  56.             macro_message = "The previous operation does not have any parts clocked in"
  57.         end if
  58.     else
  59.         Set com2 = CreateObject("adodb.command")
  60.         com2.CommandType = 1 'adCmdText
  61.         Set com2.ActiveConnection = c
  62.         com2.CommandText = qry3
  63.         com2.Parameters.Append com2.CreateParameter("wo", 200,1, 25,WORKORDER_BASE_ID)'("@wo,adVarChar,adParamInput,25)
  64.         'set rs2 = com2.execute
  65.         set rs2 = createobject("adodb.recordset")
  66.         rs2.open com2,,3,1 'com2,c,adOpenStatic,adLockReadOnly
  67.         if rs2.recordcount > 0 then
  68.             if rs3.recordcount > 0 then
  69.                 if rs2("Desired_qty") < good_qty + bad_qty + rs3("good_qty") + rs3("BAD_QTY") then
  70.                     macro_success = false
  71.                     macro_message = "The quantity good (" & good_qty & ") + the quantity bad (" & bad_qty & ") + already clocked in quantity good (" & rs3("good_qty") & ") + already clocked in quantity bad (" & rs3("bad_qty") & ") Totaled(" & (good_qty + bad_qty + rs3("good_qty") + rs3("BAD_QTY")) & ") are greater than the Work Order quantity (" & rs2("Desired_qty") & ")"
  72.                 else
  73.                     macro_success = true
  74.                 end if
  75.             else
  76.                 if rs2("Desired_qty") < good_qty + bad_qty then
  77.                     macro_success = false
  78.                     macro_message = "The quantity good (" & good_qty & ") + the quantity bad (" & bad_qty & ") Totaled(" & (good_qty + bad_qty) & ") are greater than the Work Order quantity (" & rs2("Desired_qty") & ")"
  79.                 else
  80.                     macro_success = true
  81.                 end if
  82.             end if
  83.         else
  84.             macro_success = false
  85.             macro_message = "Invalid Work Order is nothing " & (rs2 is nothing) & " rc" & rs.recordcount & " eof " & rs.eof & " bof " & rs.bof & " state " & rs.state & " dq " & rs2("Desired_qty")'how the heck does the quantity even work?!
  86.         end if
  87.     end if
  88.  
  89.     c.Close
  90.     Set rs = Nothing
  91.     set rs2 = nothing
  92.     set rs3 = nothing
  93.     Set c = Nothing
  94.     Set com = Nothing
  95.     set com2 = nothing
  96.  
  97. end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement