Link Criteria using option groupp and txt box

S

SoggyCashew

Ok, I have a form frmSwitchboard with an option group optClassicficationGroup
with eight option values that I want to use as part of a search and a Combo
box named cboFindByEmployeeName with employees names would be used also. Now I
have a button that would be used called cmdFindClassicfication and in the
buttons OnClick event I have: (Only case 1 is shown) My question is how
would I also add the the option value as part of the stLinkCritera and if an
option isnt selected how could I bring up a msgbox like the one used for the
employee cbo box and set focus to that option? Thanks!


Private Sub cmdFindClassicfication_Click()
Dim stDocName As String
Dim stLinkCriteria As String

Select Case Me.optClassicficationGroup

Case 1

If Me.cboFindByEmployeeName & "" <> "" Then
stDocName = "frmSearchEntries"
stLinkCriteria = "[EmployeeName]=" & "'" & Me![cboFindByEmployeeName] &
"'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Me.Visible = False

Else
MsgBox "You Must Enter a Date.", vbOKOnly, "Date Not Entered"
Me.cboFindByEmployeeName.SetFocus
End If

Case 2

Case 3

Case 4

End Select

End Sub
 
K

Ken Snell \(MVP\)

One can "chain" multiple filtering values in the stLinkCriteria variable
this way:

stLinkCriteria = "[EmployeeName]=" & "'" & Me![cboFindByEmployeeName] &
"' And [FieldName]=" & Me.optClassificationGroup

And so on.

To trap for "no value" for optClassificationGroup, just include all the
"good" values in the Case statement, and then add a "Case Else" line to trap
for any value that is not listed (e.g., Null).
 
S

SoggyCashew

Ken I got it to wor using code below. I used each options labels tag to give
me the name:
Private Sub optClassicficationGroup_AfterUpdate()

'// retrievs the labels tag in the option group optClassicficationGroup
'and puts the value in the txt box txtClassicficationName

If Nz(Me.optClassicficationGroup.Value, 0) > 0 Then
Me.txtClassicficationName = Me.Controls("optClassGroup" & _
optClassicficationGroup.Value).Tag
End If
End Sub

(Then I ran the code below in my button "Works great")


Private Sub cmdFindClassicfication_Click()
On Error GoTo Err_cmdFindClassicfication_Click

'//Opens frmSearchEntries linking a criteria

Dim Cri As String

If IsNull(Me.cboFindByEmployeeName) Then
MsgBox "Please select a Employee!", vbCritical, "Selection Error"
Me.cboFindByEmployeeName.SetFocus

Exit Sub
End If

If IsNull(Me.txtClassicficationName) Then
MsgBox "Please select a Classification!", vbCritical, "Selection Error"
Me.optClassicficationGroup.SetFocus

Exit Sub
End If

Cri = "Employee=" & Me![cboFindByEmployeeName] & " AND
AccidentTypeName=" & "'" & Me![txtClassicficationName] & "'"
'MsgBox (Cri)
DoCmd.OpenForm "frmSearchEntries", , , Cri

'Hides frmSwitchboard
Me.Visible = False

Exit_cmdFindClassicfication_Click:
Exit Sub

Err_cmdFindClassicfication_Click:
MsgBox Err.Description
Resume Exit_cmdFindClassicfication_Click
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top