KySoto

Monster Visual Macro

Jul 13th, 2018
184
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 out 'As ADODB.Recordset
  5. dim out2
  6. dim out3
  7. 'Queries in one place
  8. dim qry
  9. dim qry2
  10. dim qry3
  11.  
  12. If not(GOOD_QTY = 0 and BAD_QTY = 0) Then
  13.     qry = "SELECT DISTINCT TOP 1 SEQUENCE_NO FROMOPERATION WHERE (WORKORDER_BASE_ID = ?) AND (WORKORDER_LOT_ID = ?)  AND (WORKORDER_SPLIT_ID = ?) AND (WORKORDER_SUB_ID = ?) and(SEQUENCE_NO < ?)  ORDER BY SEQUENCE_NO DESC"
  14.     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 = ?)"
  15.     qry3 = "Select Desired_qty from Work_Order where Base_ID = ?"
  16.  
  17.     Set c = CreateObject("ADODB.Connection")
  18.     c.ConnectionString = "Provider=SQLOLEDB;Server=DB3;Database=VMFG1;Integrated Security = SSPI"
  19.     Set com = CreateObject("adodb.command")
  20.     com.CommandType = 1 'adCmdText
  21.     c.Open
  22.     Set com.ActiveConnection = c
  23.     com.CommandText = qry
  24.  
  25.     com.Parameters.Append = com.CreateParameter("wo", 200,1, 25,WORKORDER_BASE_ID) '("@wo,adVarChar,adParamInput,25,WORKORDER_BASE_ID)
  26.     com.Parameters.Append = com.CreateParameter("lot", 200,1, 25,WORKORDER_LOT_ID) '("@lot,adVarChar,adParamInput,25,WORKORDER_LOT_ID)
  27.     com.Parameters.Append = com.CreateParameter("split", 200,1, 25,WORKORDER_SPLIT_ID) '("@split,adVarChar,adParamInput,25,WORKORDER_SPLIT_ID)
  28.     com.Parameters.Append = com.CreateParameter("sub", 200,1, 25,WORKORDER_SUB_ID) '("@sub,adVarChar,adParamInput,25,WORKORDER_SUB_ID)
  29.     com.Parameters.Append = com.CreateParameter("op", 3, 1,,OPERATION_SEQ_NO) '("@op,adInteger,adParamInput,OPERATION_SEQ_NO)
  30.     set out = com.Execute
  31.     com.commandtext = qry3
  32.     set out3 = com.execute
  33.     if  out.recordcount > 0 then
  34.         com.parameters(4).value = out(OPERATION_SEQ_NO)
  35.         com.commandtext = qry2
  36.         set out2 = com.execute
  37.         if out2.recordcount > 0 then
  38.             if out3.recordcount > 0 then
  39.                 if out2("good_qty") < good_qty + bad_qty + out3("good_qty") + out3("BAD_QTY") then
  40.                     macro_success = false
  41.                     macro_message = "The quantity good (" & good_qty & ") + the quantity bad (" & bad_qty & ") + already clocked in quantity good (" & out3("good_qty") & ") + already clocked in quantity bad (" & out3("bad_qty") & ") Totaled(" & (good_qty + bad_qty + out3("good_qty") + out3("BAD_QTY")) & ") are greater than the previous Operation (" & out2("good_qty") & ")"
  42.                 else
  43.                     macro_success = true
  44.                 end if
  45.             else
  46.                 if out2("good_qty") < good_qty + bad_qty then
  47.                     macro_success = false
  48.                     macro_message = "The quantity good (" & good_qty & ") + the quantity bad (" & bad_qty & ") Totaled(" & (good_qty + bad_qty) & ") are greater than the previous Operation (" & out2("good_qty") & ")"
  49.                 else
  50.                     macro_success = true
  51.                 end if
  52.             end if 
  53.         else
  54.             macro_success = false
  55.             macro_message = "The previous operation does not have any parts clocked in"
  56.         end if
  57.     else
  58.         Set com2 = CreateObject("adodb.command")
  59.         com2.CommandType = 1 'adCmdText
  60.         Set com2.ActiveConnection = c
  61.         com2.CommandText = qry3
  62.         com2.Parameters.Append = com.CreateParameter("wo", 200,1, 25,WORKORDER_BASE_ID)'("@wo,adVarChar,adParamInput,25)
  63.         set out2 = com2.execute
  64.         if out2.recordcount > 0 then
  65.             if out3.recordcount > 0 then
  66.                 if out2("Desired_qty") < good_qty + bad_qty + out3("good_qty") + out3("BAD_QTY") then
  67.                     macro_success = false
  68.                     macro_message = "The quantity good (" & good_qty & ") + the quantity bad (" & bad_qty & ") + already clocked in quantity good (" & out3("good_qty") & ") + already clocked in quantity bad (" & out3("bad_qty") & ") Totaled(" & (good_qty + bad_qty + out3("good_qty") + out3("BAD_QTY")) & ") are greater than the Work Order quantity (" & out2("Desired_qty") & ")"
  69.                 else
  70.                     macro_success = true
  71.                 end if
  72.             else
  73.                 if out2("Desired_qty") < good_qty + bad_qty
  74.                     macro_success = false
  75.                     macro_message = "The quantity good (" & good_qty & ") + the quantity bad (" & bad_qty & ") Totaled(" & (good_qty + bad_qty) & ") are greater than the Work Order quantity (" & out2("Desired_qty") & ")"
  76.                 else
  77.                     macro_success = true
  78.                 end if
  79.             end if
  80.         else
  81.             macro_success = false
  82.             macro_message = "Invalid Work Order"
  83.         end if
  84.     end if
  85.  
  86.     c.Close
  87.     Set out = Nothing
  88.     set out2 = nothing
  89.     set out3 = nothing
  90.     Set c = Nothing
  91.     Set com = Nothing
  92.     set com2 = nothing
  93.  
  94. end if
Advertisement
Add Comment
Please, Sign In to add comment