M
miss031
I have seen this covered a few times, but I can't find a solution for me.
I have a form with an unbound subform. The user selects a record from a
search subformat the top, which sets that eord as the filter for the main
form, then hits a command button that binds the unbound form to a particuar
form, filtered by the main form record. This all works good, and fast
enough, but when I try to print a report from one subform, I get the "Cannot
open any more databases" message.
The search form is based on a query, and I use the following code for
searching and clicking the [cmd_use] is what sets the filter for the main
form:
___________________________________
Private Sub cmd_search_Click()
Dim strWhere As String
Dim strWord As String
Dim varKeywords As Variant 'Array of keywords.
Dim i As Integer
Dim lngLen As Long
If Me.Dirty Then 'Save first.
Me.Dirty = False
End If
If IsNull(Me.txt_search_box) Then 'Show all if blank.
Me.Filter = 0
Me.FilterOn = True
'If Me.FilterOn Then
' Me.FilterOn = False
'Else
'End If
Else
varKeywords = Split(Me.txt_search_box, " ")
If UBound(varKeywords) >= 33 Then '99 max ORs.
MsgBox "Too many words."
Else
'Build up the Where string from the array.
For i = LBound(varKeywords) To UBound(varKeywords)
strWord = Trim$(varKeywords(i))
If strWord <> vbNullString Then
strWhere = strWhere & "([lastname] Like ""*" & strWord & _
"*"") OR ([contactcompany] Like ""*" & strWord &
"*"") OR ([FirstOfphone_number_] Like ""*" & strWord & "*"") OR
([bidder_number] Like ""*" & strWord & "*"") OR ([seller_number] Like ""*" &
strWord & "*"") OR "
End If
Next
lngLen = Len(strWhere) - 4 'Without trailing " OR ".
If lngLen > 0 Then
Me.Filter = Left(strWhere, lngLen)
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End If
End If
' Me.Parent![frm_cont_bid_number_subf]![cbo_bid_number_ID].SetFocus
End Sub
Private Sub cmd_use_Click()
On Error GoTo Err_cmd_use_Click
Forms("add_new_all").Filter = "contact_ID =" & Me.contactID_current
Forms("add_new_all").FilterOn = True
Me.Parent![frame_choose_sub].SetFocus
'Forms![add_new_all].subf_main_blank.Form.Requery
Me.Filter = "contact_ID = 0"
Me.txt_sum_records = Null
Exit_cmd_use_Click:
Exit Sub
Err_cmd_use_Click:
MsgBox Err.Description
Resume Exit_cmd_use_Click
End Sub
_____________________________________
The code that binds the unbound subform is as follows:
______________________________________
Private Sub frame_choose_sub_AfterUpdate()
On Error GoTo Err_frame_choose_sub_AfterUpdate
Dim strMsg As String
Dim strWhere As String 'added
strWhere = "contact_ID = " & Forms![add_new_all].contact_ID
If frame_choose_sub = 1 Then
Forms![add_new_all].subf_main_blank.Visible = True
Forms![add_new_all].subf_main_blank.SourceObject =
"subf_main_contact_info"
Forms![add_new_all].subf_main_blank.LinkMasterFields = "contact_ID"
Forms![add_new_all].subf_main_blank.LinkChildFields = "contact_ID"
Forms![add_new_all].subf_main_blank.Form![txt_seller_number] = Null
Forms![add_new_all].subf_main_blank.Form![txt_bidder_number] = Null
'Forms![add_new_all].subf_main_blank.Form![Dummy] = 1
ElseIf frame_choose_sub = 2 Then
Forms![add_new_all].subf_main_blank.Visible = True
Forms![add_new_all].subf_main_blank.SourceObject = "subf_main_cashiering"
Forms![add_new_all].subf_main_blank.LinkMasterFields = "contact_ID"
Forms![add_new_all].subf_main_blank.LinkChildFields = "contact_ID"
ElseIf frame_choose_sub = 3 Then
Forms![add_new_all].subf_main_blank.Visible = True
Forms![add_new_all].subf_main_blank.SourceObject = "subf_main_payouts"
Forms![add_new_all].subf_main_blank.LinkMasterFields = "contact_ID"
Forms![add_new_all].subf_main_blank.LinkChildFields = "contact_ID"
End If
Exit_frame_choose_sub_AfterUpdate:
Exit Sub
Err_frame_choose_sub_AfterUpdate:
MsgBox Err.Description
Resume Exit_frame_choose_sub_AfterUpdate
End Sub
_________________________________
Do I need to close the recordset each time I switch subform source objects?
I had domain aggregates in my recordsource queries, but I changed them to
calculate on the forms and reports instead, correct?
Let me know what else you need to know. Please help, I'm lost!
I have a form with an unbound subform. The user selects a record from a
search subformat the top, which sets that eord as the filter for the main
form, then hits a command button that binds the unbound form to a particuar
form, filtered by the main form record. This all works good, and fast
enough, but when I try to print a report from one subform, I get the "Cannot
open any more databases" message.
The search form is based on a query, and I use the following code for
searching and clicking the [cmd_use] is what sets the filter for the main
form:
___________________________________
Private Sub cmd_search_Click()
Dim strWhere As String
Dim strWord As String
Dim varKeywords As Variant 'Array of keywords.
Dim i As Integer
Dim lngLen As Long
If Me.Dirty Then 'Save first.
Me.Dirty = False
End If
If IsNull(Me.txt_search_box) Then 'Show all if blank.
Me.Filter = 0
Me.FilterOn = True
'If Me.FilterOn Then
' Me.FilterOn = False
'Else
'End If
Else
varKeywords = Split(Me.txt_search_box, " ")
If UBound(varKeywords) >= 33 Then '99 max ORs.
MsgBox "Too many words."
Else
'Build up the Where string from the array.
For i = LBound(varKeywords) To UBound(varKeywords)
strWord = Trim$(varKeywords(i))
If strWord <> vbNullString Then
strWhere = strWhere & "([lastname] Like ""*" & strWord & _
"*"") OR ([contactcompany] Like ""*" & strWord &
"*"") OR ([FirstOfphone_number_] Like ""*" & strWord & "*"") OR
([bidder_number] Like ""*" & strWord & "*"") OR ([seller_number] Like ""*" &
strWord & "*"") OR "
End If
Next
lngLen = Len(strWhere) - 4 'Without trailing " OR ".
If lngLen > 0 Then
Me.Filter = Left(strWhere, lngLen)
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End If
End If
' Me.Parent![frm_cont_bid_number_subf]![cbo_bid_number_ID].SetFocus
End Sub
Private Sub cmd_use_Click()
On Error GoTo Err_cmd_use_Click
Forms("add_new_all").Filter = "contact_ID =" & Me.contactID_current
Forms("add_new_all").FilterOn = True
Me.Parent![frame_choose_sub].SetFocus
'Forms![add_new_all].subf_main_blank.Form.Requery
Me.Filter = "contact_ID = 0"
Me.txt_sum_records = Null
Exit_cmd_use_Click:
Exit Sub
Err_cmd_use_Click:
MsgBox Err.Description
Resume Exit_cmd_use_Click
End Sub
_____________________________________
The code that binds the unbound subform is as follows:
______________________________________
Private Sub frame_choose_sub_AfterUpdate()
On Error GoTo Err_frame_choose_sub_AfterUpdate
Dim strMsg As String
Dim strWhere As String 'added
strWhere = "contact_ID = " & Forms![add_new_all].contact_ID
If frame_choose_sub = 1 Then
Forms![add_new_all].subf_main_blank.Visible = True
Forms![add_new_all].subf_main_blank.SourceObject =
"subf_main_contact_info"
Forms![add_new_all].subf_main_blank.LinkMasterFields = "contact_ID"
Forms![add_new_all].subf_main_blank.LinkChildFields = "contact_ID"
Forms![add_new_all].subf_main_blank.Form![txt_seller_number] = Null
Forms![add_new_all].subf_main_blank.Form![txt_bidder_number] = Null
'Forms![add_new_all].subf_main_blank.Form![Dummy] = 1
ElseIf frame_choose_sub = 2 Then
Forms![add_new_all].subf_main_blank.Visible = True
Forms![add_new_all].subf_main_blank.SourceObject = "subf_main_cashiering"
Forms![add_new_all].subf_main_blank.LinkMasterFields = "contact_ID"
Forms![add_new_all].subf_main_blank.LinkChildFields = "contact_ID"
ElseIf frame_choose_sub = 3 Then
Forms![add_new_all].subf_main_blank.Visible = True
Forms![add_new_all].subf_main_blank.SourceObject = "subf_main_payouts"
Forms![add_new_all].subf_main_blank.LinkMasterFields = "contact_ID"
Forms![add_new_all].subf_main_blank.LinkChildFields = "contact_ID"
End If
Exit_frame_choose_sub_AfterUpdate:
Exit Sub
Err_frame_choose_sub_AfterUpdate:
MsgBox Err.Description
Resume Exit_frame_choose_sub_AfterUpdate
End Sub
_________________________________
Do I need to close the recordset each time I switch subform source objects?
I had domain aggregates in my recordsource queries, but I changed them to
calculate on the forms and reports instead, correct?
Let me know what else you need to know. Please help, I'm lost!