Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. strSQL = "SELECT [id] FROM quotation WHERE substring(reference ,3 ,len(reference)) = " & jobno & " AND version = " & ver
  2.  
  3. strSQL = "SELECT [id] FROM quotation WHERE Right(reference, 6) = " & jobno & " AND version = " & ver & " ORDER BY [createdDate]
  4.  
  5. Private Function descriptions(ByVal x As Double, y As Double, w As Double, h As Double, jobno As String, ver As String)
  6. 'On Error GoTo ex
  7. ActiveDocument.ReferencePoint = cdrTopLeft
  8. Dim objConn As New ADODB.Connection
  9. Dim objRS As New ADODB.Recordset
  10. Dim objCmd As New ADODB.Command
  11.  
  12.  
  13.  
  14. Dim strSQL As String, path As String
  15. Dim bol As Boolean
  16. Dim recordsCounter As Long, a As Long, b As Long
  17. Dim fieldvalue As Variant
  18. Dim QR As String
  19. Dim dat As Variant
  20. Dim FULLID As String
  21. Dim i As Long, j As Long, k As Long
  22.  
  23.  
  24. 'CONNECT TO SERVER AND DB
  25. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  26.  
  27.  
  28. With objConn
  29. .Provider = "SQLOLEDB.1;Password=xxxxxxxxxxxxxxxxxxx;Persist Security Info=True;User ID=xxxxxxxxxxxxxxxxxxx;Initial Catalog=xxxxxxxxxx;"
  30. .ConnectionString = "Data Source=xxxxxxxxxxxxxxxxxxx;"
  31. .Open
  32. End With
  33.  
  34. If objConn.State <> 1 Then MsgBox "You were unable to connect to the database!", vbInformation
  35.  
  36. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  37.  
  38. strSQL = "SELECT [id] FROM quotation WHERE substring(reference ,3 ,len(reference)) = " & jobno & " AND version = " & ver
  39.  
  40. 'strSQL = "SELECT [id] FROM quotation WHERE Right(reference, 6) = " & jobno & " AND version = " & ver & " ORDER BY [createdDate]
  41.  
  42. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  43.  
  44. objRS.Open strSQL, objConn, adOpenKeyset, adLockOptimistic
  45. QR = objRS.Fields(0).Value
  46. FULLID = objRS.Fields(1).Value
  47. MsgBox FULLID
  48.  
  49. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  50. strSQL = "SELECT [itemId], [quantity], [description] FROM quotationitems WHERE quotationid = " & [QR] & " ORDER BY [itemId];"
  51. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  52.  
  53. objRS.Close
  54. objRS.Open strSQL, objConn, adOpenKeyset, adLockOptimistic
  55.  
  56.  
  57.  
  58.  
  59. 'RETRIEVE DESCRIPTIONS
  60. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  61.  
  62.  
  63. Dim DX As Double, DY As Double, DW As Double, DH As Double
  64. Dim drx As Double, dry As Double, drw As Double, drh As Double
  65. Dim DESCRIP As New ShapeRange
  66. Dim s1 As Shape
  67. Dim descriprange As Shape
  68. Dim DLINE As String
  69.  
  70. Dim Desc As String, itm As String, quantity As String
  71.  
  72. DX = x + (w * 0.005)
  73. DY = y + (h * 0.001)
  74.  
  75. Do While Not objRS.EOF
  76.  
  77. If objRS.Fields(0).Value <> -1 Then itm = Chr(64 + objRS.Fields(0).Value)
  78. If objRS.Fields(1).Value <> -1 Then quantity = objRS.Fields(1)
  79. If objRS.Fields(2).Value <> -1 Then Desc = objRS.Fields(2)
  80. DLINE = "ITEM " & replace(itm, vbCr, " ") & " Qty: " & quantity & " " & Chr(13) & Desc
  81.  
  82.  
  83.  
  84. Set s1 = ActiveLayer.FindShape("DESCRIPTIONENTRYPOINT")
  85. s1.Duplicate
  86. s1.TEXT.Story = DLINE
  87. s1.TEXT.Story = replace(s1.TEXT.Story, vbCr & vbCr, "")
  88. s1.TEXT.Story = replace(s1.TEXT.Story, "ITEM ", vbCr & vbCr & "ITEM ")
  89. DESCRIP.Add s1
  90. DY = DY - (s1.SizeHeight * 1.1)
  91. s1.ObjectData("Name") = "DESCRIPTION-PARAGRAPH"
  92.  
  93.  
  94. recordsCounter = recordsCounter + 1
  95. objRS.MoveNext
  96.  
  97. Loop
  98. objRS.Close
  99.  
  100. Dim TRS As ShapeRange
  101. Set TRS = ActiveLayer.FindShapes("DESCRIPTIONENTRYPOINT")
  102. TRS.Delete
  103.  
  104. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  105.  
  106.  
  107. 'POSITION + SCALE DESCRIPTION TEXT TO SUIT TEMPLATE
  108. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  109.  
  110. DESCRIP.GetBoundingBox DX, DY, DW, DH, False
  111. DESCRIP.CreateSelection
  112. Set DESCRIP = ActiveSelectionRange.ReverseRange
  113.  
  114. Set descriprange = ActiveLayer.FindShape("DESCRANGE")
  115. descriprange.GetBoundingBox drx, dry, drw, drh, False
  116.  
  117.  
  118. Dim TXT2 As Shape
  119.  
  120. For Each TXT2 In DESCRIP
  121.  
  122. TXT2.TEXT.ConvertToParagraph
  123. TXT2.ObjectData("Name") = "DESCRIPTION-PARAGRAPH"
  124.  
  125. Next TXT2
  126.  
  127.  
  128. DESCRIP.Combine
  129.  
  130.  
  131.  
  132. DESCRIP.SetSize drw, drh
  133. DESCRIP.SetPosition drx, dry + drh
  134.  
  135.  
  136. FINE2:
  137.  
  138.  
  139.  
  140. 'TIDY GROUPS ADD ADD DESCRIPTION TO TEMPLATE GROUP
  141. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  142. Dim FINDTEMP As Shape
  143. Set FINDTEMP = ActivePage.FindShape(name:="template")
  144. Dim regrouped As Shape
  145. Dim regrouper As ShapeRange
  146. Set regrouper = FINDTEMP.UngroupAllEx
  147. DESCRIP.CreateSelection
  148. regrouper.Add ActiveSelection
  149.  
  150. Set regrouped = regrouper.Group
  151. regrouped.ObjectData("Name") = "template"
  152. regrouper.RemoveAll
  153.  
  154.  
  155.  
  156.  
  157. Set objCmd = Nothing
  158. Set objRS = Nothing
  159. Set objConn = Nothing
  160. ex:
  161. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement