Populating Elements
Submitted by kevern010101 on Saturday, October 9, 2010 - 07:17.
- Option Explicit
- Dim conn As ADODB.Connection
- Dim rs As ADODB.Recordset
- ' pupulate element
- ' @author: Kevern
- ' @date: checkDate 07/28/2009
- Public Sub init()
- Set conn = New ADODB.Connection
- Set rs = New ADODB.Recordset
- conn.connectionString = ConnectionStringModule.connectionString
- With conn
- On Error GoTo errHandler
- .Open
- End With
- Exit Sub
- errHandler:
- MsgBox Err.Description, vbCritical + vbOKOnly, "Admin: Populate Element MOdule - Init"
- End Sub
- Public Sub populateFlexGrids(dboquery As String, grid As MSHFlexGrid)
- Call init
- grid.Clear
- With rs
- On Error GoTo errHandler
- .Open dboquery, conn, adOpenKeyset, adLockOptimistic
- If rs.RecordCount = 0 Then
- MsgBox "No Data Found!", vbCritical, "Admin: Populate Element MOdule - Populate Flexgrid"
- Set grid.DataSource = rs
- Else
- Set grid.DataSource = rs
- End If
- .Close
- End With
- conn.Close
- Dim columnWidth As Double
- Dim counter As Integer
- columnWidth = (grid.Width / grid.Cols)
- If columnWidth <= 2000 Then
- columnWidth = 2000
- End If
- For counter = 0 To grid.Cols
- grid.ColWidth(counter) = columnWidth
- Next counter
- grid.Refresh
- Exit Sub
- errHandler:
- MsgBox Err.Description, vbCritical + vbOKOnly, "Admin: Populate Element MOdule - Populate Flexgrid: Error"
- End Sub
- Public Sub populatePickingList(dboquery As String, grid As MSHFlexGrid)
- Call init
- grid.Clear
- With rs
- On Error Resume Next
- .Open dboquery, conn, adOpenKeyset, adLockOptimistic
- Set grid.DataSource = rs
- .Close
- End With
- Dim counter As Integer
- With grid
- For counter = 0 To grid.Cols - 1
- .ColWidth(counter) = 2000
- Next counter
- End With
- conn.Close
- End Sub
- Public Sub populateCombo(KeyToCollect As String, dboquery As String, combo As ComboBox)
- Call init
- combo.Clear
- With rs
- 'On Error GoTo errHandler
- On Error Resume Next
- If .State = adStateClosed Then
- .Open dboquery, conn, adOpenKeyset, adLockOptimistic
- End If
- Do While Not .EOF
- combo.addItem .fields(KeyToCollect)
- .MoveNext
- Loop
- .Close
- End With
- conn.Close
- Exit Sub
- errHandler:
- MsgBox Err.Description, vbCritical + vbOKOnly, " Admin: Populate Element MOdule - Populate Combo: Error"
- End Sub
- Public Sub setText(dboquery As String, txtBox As TextBox, fieldCollect As String)
- Call init
- With rs
- 'On Error GoTo errHandler
- On Error Resume Next
- If .State = adStateClosed Then
- .Open dboquery, conn, adOpenKeyset, adLockOptimistic
- End If
- If .EOF Then
- MsgBox "Request unavailable on other tables, cannot populate other elements!"
- .Close
- conn.Close
- Exit Sub
- Else
- txtBox.Text = .fields(fieldCollect)
- End If
- .Close
- End With
- conn.Close
- Exit Sub
- errHandler:
- MsgBox Err.Description, vbCritical + vbOKOnly, "Admin: Populate Element MOdule - Set Text: Error"
- End Sub
- Public Sub setcomboText(dboquery As String, cbo As ComboBox, fieldCollect As String)
- Call init
- With rs
- 'On Error GoTo errHandler
- On Error Resume Next
- If .State = adStateClosed Then
- .Open dboquery, conn, adOpenKeyset, adLockOptimistic
- End If
- If .EOF Then
- MsgBox "Request unavailable on other tables, cannot populate other elements!"
- .Close
- conn.Close
- cbo.Text = ""
- Exit Sub
- Else
- cbo.Text = .fields(fieldCollect)
- End If
- .Close
- End With
- conn.Close
- Exit Sub
- errHandler:
- MsgBox Err.Description, vbCritical + vbOKOnly, "Admin: Populate Element MOdule - Set Combo: Error"
- End Sub
- Public Sub setDate(dboquery As String, DTP As DTPicker, fieldCollect As String)
- Call init
- With rs
- On Error GoTo errHandler
- .Open dboquery, conn, adOpenKeyset, adLockOptimistic
- DTP.value = .fields(fieldCollect)
- .Close
- End With
- conn.Close
- Exit Sub
- errHandler:
- MsgBox Err.Description, vbCritical + vbOKOnly, " Admin: Populate Element MOdule - Set Date: Error"
- End Sub
Add new comment
- 10 views