I have a subform that retrieves specific fields from a table depending on the criteria the user enters and the projectid that they select. Now I don't understand why it doesn't work!!!
Here is the code that I wrote when you press the Search button:
Private Sub cmdSearch_Click()
Dim strSearch As String
Dim strProjectId As String
Dim strSqlQry As String
If IsNull(cmbProjectID) Then
MsgBox "you must select a project"
cmbProjectID.SetFocus
Exit Sub
End If
If IsNull(txtSearch) Then
MsgBox "Must enter a criteria"
txtSearch.SetFocus
Exit Sub
End If
strSearch = txtSearch.Value
strProjectId = cmbProjectID.Value
Dim conn As ADODB.Connection
Set conn = CurrentProject.Connection
'get all the info that corresponds to the criteria and insert it into the temporary table
Dim rsQry As ADODB.Recordset
Set rsQry = New Recordset
strSqlQry = "Select * from activities where wbs like '" & strSearch & "' and projectid = '" & strProjectId & "'"
rsQry.Open strSqlQry, conn, adOpenStatic, adLockOptimistic
If strSearch = "*" Then
Form_CalculationsSubform.Form.RecordSource = "Select * from activities where wbs not like '_INITIAL' and projectid = '" & strProjectId & "'"
Else
Form_CalculationsSubform.Form.RecordSource = "Select * from activities where wbs like '" & strSearch & "' and projectid = '" & strProjectId & "'"
End If
End Sub
I don't understand why it doesn't work if i use another subform to retrieve something else but the criterias that I am using are the same.
Here is the code that I wrote when you press the Search button:
Private Sub cmdSearch_Click()
Dim strSearch As String
Dim strProjectId As String
Dim strSqlQry As String
If IsNull(cmbProjectID) Then
MsgBox "you must select a project"
cmbProjectID.SetFocus
Exit Sub
End If
If IsNull(txtSearch) Then
MsgBox "Must enter a criteria"
txtSearch.SetFocus
Exit Sub
End If
strSearch = txtSearch.Value
strProjectId = cmbProjectID.Value
Dim conn As ADODB.Connection
Set conn = CurrentProject.Connection
'get all the info that corresponds to the criteria and insert it into the temporary table
Dim rsQry As ADODB.Recordset
Set rsQry = New Recordset
strSqlQry = "Select * from activities where wbs like '" & strSearch & "' and projectid = '" & strProjectId & "'"
rsQry.Open strSqlQry, conn, adOpenStatic, adLockOptimistic
If strSearch = "*" Then
Form_CalculationsSubform.Form.RecordSource = "Select * from activities where wbs not like '_INITIAL' and projectid = '" & strProjectId & "'"
Else
Form_CalculationsSubform.Form.RecordSource = "Select * from activities where wbs like '" & strSearch & "' and projectid = '" & strProjectId & "'"
End If
End Sub
I don't understand why it doesn't work if i use another subform to retrieve something else but the criterias that I am using are the same.