Populating Elements

  1. Option Explicit
  2.     Dim conn As ADODB.Connection
  3.     Dim rs As ADODB.Recordset
  4.    
  5.    
  6.    
  7.    
  8. ' pupulate element
  9. ' @author: Kevern
  10. ' @date: checkDate 07/28/2009
  11. Public Sub init()
  12.     Set conn = New ADODB.Connection
  13.     Set rs = New ADODB.Recordset
  14.         conn.connectionString = ConnectionStringModule.connectionString
  15.             With conn
  16.                 On Error GoTo errHandler
  17.                 .Open
  18.             End With
  19.         Exit Sub
  20. errHandler:
  21.     MsgBox Err.Description, vbCritical + vbOKOnly, "Admin: Populate Element MOdule - Init"
  22. End Sub
  23. Public Sub populateFlexGrids(dboquery As String, grid As MSHFlexGrid)
  24.     Call init
  25.     grid.Clear
  26.         With rs
  27.             On Error GoTo errHandler
  28.             .Open dboquery, conn, adOpenKeyset, adLockOptimistic
  29.             If rs.RecordCount = 0 Then
  30.                 MsgBox "No Data Found!", vbCritical, "Admin: Populate Element MOdule - Populate Flexgrid"
  31.                 Set grid.DataSource = rs
  32.             Else
  33.                 Set grid.DataSource = rs
  34.             End If
  35.             .Close
  36.         End With
  37.         conn.Close
  38.     Dim columnWidth As Double
  39.     Dim counter As Integer
  40.             columnWidth = (grid.Width / grid.Cols)
  41.             If columnWidth <= 2000 Then
  42.                 columnWidth = 2000
  43.             End If
  44.             For counter = 0 To grid.Cols
  45.                 grid.ColWidth(counter) = columnWidth
  46.             Next counter
  47.         grid.Refresh
  48.     Exit Sub
  49. errHandler:
  50.     MsgBox Err.Description, vbCritical + vbOKOnly, "Admin: Populate Element MOdule - Populate Flexgrid: Error"
  51. End Sub
  52. Public Sub populatePickingList(dboquery As String, grid As MSHFlexGrid)
  53.     Call init
  54.     grid.Clear
  55.     With rs
  56.            On Error Resume Next
  57.            .Open dboquery, conn, adOpenKeyset, adLockOptimistic
  58.            Set grid.DataSource = rs
  59.     .Close
  60.     End With
  61.    
  62.     Dim counter As Integer
  63.     With grid
  64.         For counter = 0 To grid.Cols - 1
  65.             .ColWidth(counter) = 2000
  66.         Next counter
  67.     End With
  68.    
  69.     conn.Close
  70. End Sub
  71. Public Sub populateCombo(KeyToCollect As String, dboquery As String, combo As ComboBox)
  72.     Call init
  73.     combo.Clear
  74.             With rs
  75.                 'On Error GoTo errHandler
  76.                 On Error Resume Next
  77.                 If .State = adStateClosed Then
  78.                     .Open dboquery, conn, adOpenKeyset, adLockOptimistic
  79.                 End If
  80.                     Do While Not .EOF
  81.                         combo.addItem .fields(KeyToCollect)
  82.                         .MoveNext
  83.                     Loop
  84.                 .Close
  85.             End With
  86.         conn.Close
  87.     Exit Sub
  88. errHandler:
  89.     MsgBox Err.Description, vbCritical + vbOKOnly, " Admin: Populate Element MOdule - Populate Combo: Error"
  90. End Sub
  91. Public Sub setText(dboquery As String, txtBox As TextBox, fieldCollect As String)
  92.     Call init
  93.         With rs
  94.             'On Error GoTo errHandler
  95.             On Error Resume Next
  96.             If .State = adStateClosed Then
  97.                 .Open dboquery, conn, adOpenKeyset, adLockOptimistic
  98.             End If
  99.             If .EOF Then
  100.                 MsgBox "Request unavailable on other tables, cannot populate other elements!"
  101.                 .Close
  102.                 conn.Close
  103.                 Exit Sub
  104.             Else
  105.                 txtBox.Text = .fields(fieldCollect)
  106.             End If
  107.            
  108.             .Close
  109.         End With
  110.     conn.Close
  111.     Exit Sub
  112. errHandler:
  113.     MsgBox Err.Description, vbCritical + vbOKOnly, "Admin: Populate Element MOdule - Set Text: Error"
  114. End Sub
  115. Public Sub setcomboText(dboquery As String, cbo As ComboBox, fieldCollect As String)
  116.     Call init
  117.             With rs
  118.                 'On Error GoTo errHandler
  119.                 On Error Resume Next
  120.                 If .State = adStateClosed Then
  121.                     .Open dboquery, conn, adOpenKeyset, adLockOptimistic
  122.                 End If
  123.                 If .EOF Then
  124.                     MsgBox "Request unavailable on other tables, cannot populate other elements!"
  125.                     .Close
  126.                     conn.Close
  127.                     cbo.Text = ""
  128.                     Exit Sub
  129.                 Else
  130.                     cbo.Text = .fields(fieldCollect)
  131.                 End If
  132.                 .Close
  133.             End With
  134.         conn.Close
  135.     Exit Sub
  136. errHandler:
  137.     MsgBox Err.Description, vbCritical + vbOKOnly, "Admin: Populate Element MOdule - Set Combo: Error"
  138. End Sub
  139. Public Sub setDate(dboquery As String, DTP As DTPicker, fieldCollect As String)
  140.     Call init
  141.             With rs
  142.                 On Error GoTo errHandler
  143.                 .Open dboquery, conn, adOpenKeyset, adLockOptimistic
  144.                 DTP.value = .fields(fieldCollect)
  145.                 .Close
  146.             End With
  147.         conn.Close
  148.     Exit Sub
  149. errHandler:
  150.     MsgBox Err.Description, vbCritical + vbOKOnly, " Admin: Populate Element MOdule - Set Date: Error"
  151. End Sub

Add new comment