First let me say - this is a fantastic forum!!
I am trying to build a form that will use the value from 3 option groups (one of which is a ORDER BY), and also take the name from a combo box. What complicates matters is that the name can appear is one or more of 4 fields in the table. I can write the SQL, but it still doesn't seem to work (some parts do work).
The ORDER BY portion doesn't work, and the combo box gets the error "you can't reference a property or method for a control unless the control has focus"
Here's my code:
Private Sub cmdDisplayRecords_Click()
On Error GoTo Err_cmdDisplayRecords_Click
Dim strOrderBy As String
Dim strPeople As String
Dim strFormName As String
Dim strLinkCriteria As String
'create criteria based on user selection - THIS PART WORKS GREAT!
Select Case fraContract
Case 1
strLinkCriteria = "tblProjects.txtClient = 'Liberty II'"
Case 2
strLinkCriteria = "tblProjects.txtClient = 'Prop2003'"
Case 3
strLinkCriteria = "tblProjects.txtSiteStatus <> 'dead'"
Case Else
MsgBox "You must select a form", vbExclamation, "Open Form"
End Select
'select only records by combo box selection, if selected
If cboPeople.Value > 0 Then
strPeople = cboPeople.Text
End If
'add to criteria string to look in all name fields for text value
strLinkCriteria = " and tblProjects.txtProjectMgr = " & strPeople & _
" or tblProjects.txtSAID = " & strPeople & _
" or tblProjects.txtZoningInit = " & strPeople & _
" or tblProjects..txt2ndInstrInit = " & strPeople
'create sort option
Select Case fraSortOrder
Case 1
strOrderBy = " ORDER BY tblProjects.txtSite#"
Case 2
strOrderBy = " ORDER BY tblProjects.txtSiteName"
Case 3
strOrderBy = " ORDER BY tblProjects.txtBTA"
Case Else
MsgBox "How do you want records sorted?", vbExclamation, "Open Form"
End Select
'determine which form will be opened - THIS PART WORKS GREAT!
Select Case fraFormSelect
Case 1
strFormName = "frmProjectsSA&Zoning"
Case 2
strFormName = "frmProjectsArchitectural"
Case 3
strFormName = "frmProjectsPaypoint"
Case Else
MsgBox "You must select a form", vbExclamation, "Open Form"
End Select
DoCmd.OpenForm strFormName, , , strLinkCriteria & strOrderBy, acFormEdit
Exit_cmdDisplayRecords_Click:
Exit Sub
Err_cmdDisplayRecords_Click:
MsgBox Err.Description
Resume Exit_cmdDisplayRecords_Click
End Sub
I am trying to build a form that will use the value from 3 option groups (one of which is a ORDER BY), and also take the name from a combo box. What complicates matters is that the name can appear is one or more of 4 fields in the table. I can write the SQL, but it still doesn't seem to work (some parts do work).
The ORDER BY portion doesn't work, and the combo box gets the error "you can't reference a property or method for a control unless the control has focus"
Here's my code:
Private Sub cmdDisplayRecords_Click()
On Error GoTo Err_cmdDisplayRecords_Click
Dim strOrderBy As String
Dim strPeople As String
Dim strFormName As String
Dim strLinkCriteria As String
'create criteria based on user selection - THIS PART WORKS GREAT!
Select Case fraContract
Case 1
strLinkCriteria = "tblProjects.txtClient = 'Liberty II'"
Case 2
strLinkCriteria = "tblProjects.txtClient = 'Prop2003'"
Case 3
strLinkCriteria = "tblProjects.txtSiteStatus <> 'dead'"
Case Else
MsgBox "You must select a form", vbExclamation, "Open Form"
End Select
'select only records by combo box selection, if selected
If cboPeople.Value > 0 Then
strPeople = cboPeople.Text
End If
'add to criteria string to look in all name fields for text value
strLinkCriteria = " and tblProjects.txtProjectMgr = " & strPeople & _
" or tblProjects.txtSAID = " & strPeople & _
" or tblProjects.txtZoningInit = " & strPeople & _
" or tblProjects..txt2ndInstrInit = " & strPeople
'create sort option
Select Case fraSortOrder
Case 1
strOrderBy = " ORDER BY tblProjects.txtSite#"
Case 2
strOrderBy = " ORDER BY tblProjects.txtSiteName"
Case 3
strOrderBy = " ORDER BY tblProjects.txtBTA"
Case Else
MsgBox "How do you want records sorted?", vbExclamation, "Open Form"
End Select
'determine which form will be opened - THIS PART WORKS GREAT!
Select Case fraFormSelect
Case 1
strFormName = "frmProjectsSA&Zoning"
Case 2
strFormName = "frmProjectsArchitectural"
Case 3
strFormName = "frmProjectsPaypoint"
Case Else
MsgBox "You must select a form", vbExclamation, "Open Form"
End Select
DoCmd.OpenForm strFormName, , , strLinkCriteria & strOrderBy, acFormEdit
Exit_cmdDisplayRecords_Click:
Exit Sub
Err_cmdDisplayRecords_Click:
MsgBox Err.Description
Resume Exit_cmdDisplayRecords_Click
End Sub