T
TonyWilliams via AccessMonster.com
Douglas I tried this (which is some earlier code you gave me) and got a
message to say expression refers to an object that is closed or doesn't exist?
Thanks Tony
Private Sub Command36_Click()
On Error GoTo Err_Command36_Click
Dim strtxtcompany As String
Dim strtxtdate As Date
Forms!frmMain!SubForm1.SourceObject = "subformFDA"
strtxtdate = Me.txtmontha
strtxtcompany = Me.cmbselectcompany
If IsNull(Me.cmbselectcompany) Then
Forms!frmMain!SubForm1.Form.RecordSource = _
"SELECT * FROM [tblmaintabs] " & _
"WHERE [txtmonthlabel] = '" & Format(strtxtdate, "mmmm/yyyy") & "'"
Else
Forms!frmMain!SubForm1.Form.RecordSource = _
"SELECT * FROM [tblmaintabs] " & _
"WHERE [txtmonthlabel] = '" & Format(strtxtdate, "mmmm/yyyy") & "' " & _
"AND [txtcompany] = '" & strtxtcompany & "'"
End If
Exit_Command36_Click:
Exit Sub
Err_Command36_Click:
MsgBox Err.Description
Resume Exit_Command36_Click
End Sub
message to say expression refers to an object that is closed or doesn't exist?
Thanks Tony
Private Sub Command36_Click()
On Error GoTo Err_Command36_Click
Dim strtxtcompany As String
Dim strtxtdate As Date
Forms!frmMain!SubForm1.SourceObject = "subformFDA"
strtxtdate = Me.txtmontha
strtxtcompany = Me.cmbselectcompany
If IsNull(Me.cmbselectcompany) Then
Forms!frmMain!SubForm1.Form.RecordSource = _
"SELECT * FROM [tblmaintabs] " & _
"WHERE [txtmonthlabel] = '" & Format(strtxtdate, "mmmm/yyyy") & "'"
Else
Forms!frmMain!SubForm1.Form.RecordSource = _
"SELECT * FROM [tblmaintabs] " & _
"WHERE [txtmonthlabel] = '" & Format(strtxtdate, "mmmm/yyyy") & "' " & _
"AND [txtcompany] = '" & strtxtcompany & "'"
End If
Exit_Command36_Click:
Exit Sub
Err_Command36_Click:
MsgBox Err.Description
Resume Exit_Command36_Click
End Sub
You cannot assign its value to a string variable if nothing's been selected:
string variables cannot be set to Null (the only variable type that can is
Variant)
I gave you the answer days ago: you must check
If IsNull(Me.cmbselectcompany) Then
' Set strsql without reference to cmbselectcompany
Else
' Set strsql including cmbselectcompany
End If
And please listen to me when I say that you cannot use # delimiters unless
you're using a complete date, and Format(dattxtdate, "mmmm/yyyy") isn't a
complete date!
[quoted text clipped - 46 lines]Hi Douglas I used the Break in VBA to see what the values were as the code
ran and that's where I could see cmbselect=null.