M
Mekinnik via AccessMonster.com
I have two combo boxes one named cboReviewBy and the other cboReview.
cboReviewBy is populated from a table, now when the user selects one of four
choices fron the dropdown the either a query is run for that perticular
choice or combo box cboReview is populated with other choices from my main
table named tblHazinventory based on the choice from cboReviewBy. Now when
the user selects one of the choices from cboReview I want to load and fill a
form not a report based on the selection.
However when the user chooses one of the choices that runs a query I want the
query to be read only and allow the user to pick one of the rows listed to
populated the form for viewing.
I have been going back and forth with the code for days and this is as far as
I have gotten, any sugesstions to my code would be very helpful.
Option Compare Database
Private Sub cboReview_AfterUpdate()
Dim strSql As String
If Me.cboReviewBy = "" Then
strSql = "SELECT Me.cboReviewBy FROM tblHazinventory WHERE [Me.cboReview]"
End If
End Sub
Private Sub cboReviewBy_AfterUpdate()
Dim ctl1 As Control
'Assign data/display settings for Review combo box
'based on the ReviewBy combo box selection
Set ctl1 = Me.cboReview
If Me.cboReviewBy = "Unit" Then
ctl1.RowSourceType = "Table/Query"
ctl1.RowSource = "SELECT Unitname FROM tblunit "
ElseIf Me.cboReviewBy = "Department" Then
ctl1.RowSourceType = "Table/Query"
ctl1.RowSource = "SELECT department FROM department "
ElseIf Me.cboReviewBy = "Product" Then
ctl1.RowSourceType = "Table/Query"
ctl1.RowSource = "SELECT [Product name] FROM tblHazinventory "
ElseIf Me.cboReviewBy = "MSDS" Then
ctl1.RowSourceType = "Table/Query"
ctl1.RowSource = "SELECT msds FROM tblHazinventory "
End If
ctl1.ColumnCount = 1
ctl1.ColumnWidth = "0.2"
ctl1.BoundColumn = 1
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim ctl1 As Control
Dim cbo1 As ComboBox
Const conAlignRight = 3
'Position ReviewBy label 60 twips from the form's
'left border and 1 inch (1440 twips) wide
Set ctl1 = Me.lblReviewBy
ctl1.Left = 60
ctl1.Width = 1440
ctl1.Caption = "Review By:"
ctl1.TextAlign = conAlignRight
'Set ReviewBy combo box to start where the text box ends
'and set combo box's width to 1 inch (1440 twips)
Set ctl1 = Me.cboReviewBy
ctl1.Left = 60 + Me.lblReviewBy.Left + Me.lblReviewBy.Width
'Assign data/display settings for ReviewBy combo box
ctl1.RowSourceType = "Table/Query"
ctl1.RowSource = "SELECT reviewby From tblreviewby"
ctl1.ColumnCount = 1
ctl1.ColumnWidth = "0.2"
ctl1.BoundColumn = 1
'Position Review label 40 twips from right edge of
'cboReviewBy and 1 inch (1440 twips) wide
Set ctl1 = Me.lblReview
ctl1.Left = Me.cboReviewBy.Left + Me.cboReviewBy.Width + 40
ctl1.Width = Me.lblReviewBy.Width
ctl1.Caption = "Select:"
ctl1.TextAlign = conAlignRight
'Set Review combo box to start where the text box ends
'and lengthen combo box to 1.5 inches (2160 twips)
Set ctl1 = Me.cboReview
ctl1.Width = 2160
ctl1.Left = 60 + Me.lblReview.Left + Me.lblReview.Width
ctl1.Value = ""
End Sub
cboReviewBy is populated from a table, now when the user selects one of four
choices fron the dropdown the either a query is run for that perticular
choice or combo box cboReview is populated with other choices from my main
table named tblHazinventory based on the choice from cboReviewBy. Now when
the user selects one of the choices from cboReview I want to load and fill a
form not a report based on the selection.
However when the user chooses one of the choices that runs a query I want the
query to be read only and allow the user to pick one of the rows listed to
populated the form for viewing.
I have been going back and forth with the code for days and this is as far as
I have gotten, any sugesstions to my code would be very helpful.
Option Compare Database
Private Sub cboReview_AfterUpdate()
Dim strSql As String
If Me.cboReviewBy = "" Then
strSql = "SELECT Me.cboReviewBy FROM tblHazinventory WHERE [Me.cboReview]"
End If
End Sub
Private Sub cboReviewBy_AfterUpdate()
Dim ctl1 As Control
'Assign data/display settings for Review combo box
'based on the ReviewBy combo box selection
Set ctl1 = Me.cboReview
If Me.cboReviewBy = "Unit" Then
ctl1.RowSourceType = "Table/Query"
ctl1.RowSource = "SELECT Unitname FROM tblunit "
ElseIf Me.cboReviewBy = "Department" Then
ctl1.RowSourceType = "Table/Query"
ctl1.RowSource = "SELECT department FROM department "
ElseIf Me.cboReviewBy = "Product" Then
ctl1.RowSourceType = "Table/Query"
ctl1.RowSource = "SELECT [Product name] FROM tblHazinventory "
ElseIf Me.cboReviewBy = "MSDS" Then
ctl1.RowSourceType = "Table/Query"
ctl1.RowSource = "SELECT msds FROM tblHazinventory "
End If
ctl1.ColumnCount = 1
ctl1.ColumnWidth = "0.2"
ctl1.BoundColumn = 1
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim ctl1 As Control
Dim cbo1 As ComboBox
Const conAlignRight = 3
'Position ReviewBy label 60 twips from the form's
'left border and 1 inch (1440 twips) wide
Set ctl1 = Me.lblReviewBy
ctl1.Left = 60
ctl1.Width = 1440
ctl1.Caption = "Review By:"
ctl1.TextAlign = conAlignRight
'Set ReviewBy combo box to start where the text box ends
'and set combo box's width to 1 inch (1440 twips)
Set ctl1 = Me.cboReviewBy
ctl1.Left = 60 + Me.lblReviewBy.Left + Me.lblReviewBy.Width
'Assign data/display settings for ReviewBy combo box
ctl1.RowSourceType = "Table/Query"
ctl1.RowSource = "SELECT reviewby From tblreviewby"
ctl1.ColumnCount = 1
ctl1.ColumnWidth = "0.2"
ctl1.BoundColumn = 1
'Position Review label 40 twips from right edge of
'cboReviewBy and 1 inch (1440 twips) wide
Set ctl1 = Me.lblReview
ctl1.Left = Me.cboReviewBy.Left + Me.cboReviewBy.Width + 40
ctl1.Width = Me.lblReviewBy.Width
ctl1.Caption = "Select:"
ctl1.TextAlign = conAlignRight
'Set Review combo box to start where the text box ends
'and lengthen combo box to 1.5 inches (2160 twips)
Set ctl1 = Me.cboReview
ctl1.Width = 2160
ctl1.Left = 60 + Me.lblReview.Left + Me.lblReview.Width
ctl1.Value = ""
End Sub