|
|
error message 91 Object variable or With block variable not set
Access 2007
I am trying to implement the 'FindAsYouType' example below and each time I
open the form I get this error message:
"91 Object variable or With block variable not set"
From the information I have applied the changes required, 'myCombo' and
'mySearch' field into the form code but cannot see where the problem lies,
can anyone advise what is wrong
Thanks
FAYTC code >>>>>
Option Compare Database
Option Explicit
'Class Module Name: FindAsYouTypeCombo
'Purpose: Turn any combobox into a "Find As You Type" 'Combobox
'Created by: MajP
'Demonstrates: OOP, and With Events
'
'Use:To use the class, you need code similar to the 'following in a form's
module.
'Also requires a reference to DAO
'Two properties must be set: FilterComboBox
'and FilterFieldName. These are the combo box object
'and the name of the field that you are filtering.
'
'*******Start Form Code*******************
'
'Public faytCombo As FindAsYouTypeCombo
'
'Private Sub Form_Open(Cancel As Integer)
' Set faytCombo = New FindAsYouTypeCombo
' Set faytCombo.FilterComboBox = Me.myCombo
' faytCombo.FilterFieldName = "mySearch"
'End Sub
'
'******* END Form Code ******************
'
Private WithEvents mCombo As Access.ComboBox
Private WithEvents mForm As Access.Form
Private mFilterFieldName As String
Private mRsOriginalList As DAO.Recordset
Public Property Get FilterComboBox() As Access.ComboBox
Set FilterComboBox = mCombo
End Property
Public Property Set FilterComboBox(theFilterComboBox As Access.ComboBox)
On Error GoTo errLabel
If Not theFilterComboBox.RowSourceType = "Table/Query" Then
MsgBox "This class will only work with a combobox that uses a Table or
Query as the Rowsource"
Exit Property
End If
Set mCombo = theFilterComboBox
Set mForm = theFilterComboBox.Parent
mForm.OnCurrent = "[Event Procedure]"
mCombo.OnGotFocus = "[Event Procedure]"
mCombo.OnChange = "[Event Procedure]"
mCombo.AfterUpdate = "[Event Procedure]"
With mCombo
.SetFocus
.AutoExpand = False
End With
Set mRsOriginalList = mCombo.Recordset.Clone
Exit Property
errLabel:
MsgBox Err.Number & " " & Err.Description
End Property
Private Sub mCombo_Change()
Call FilterList
End Sub
Private Sub mCombo_GotFocus()
mCombo.Dropdown
End Sub
Private Sub mCombo_AfterUpdate()
Call unFilterList
End Sub
Private Sub mForm_Current()
Call unFilterList
End Sub
Private Sub FilterList()
On Error GoTo errLable
Dim rsTemp As DAO.Recordset
Dim strText As String
Dim strFilter As String
strText = mCombo.Text
If mFilterFieldName = "" Then
MsgBox "Must Supply A FieldName Property to filter list."
Exit Sub
End If
strFilter = mFilterFieldName & " like '" & strText & "*'"
Set rsTemp = mRsOriginalList.OpenRecordset
rsTemp.Filter = strFilter
Set rsTemp = rsTemp.OpenRecordset
If rsTemp.RecordCount > 0 Then
Set mCombo.Recordset = rsTemp
End If
mCombo.Dropdown
Exit Sub
errLable:
If Err.Number = 3061 Then
MsgBox "Will not Filter. Verify Field Name is Correct."
Else
MsgBox Err.Number & " " & Err.Description
End If
End Sub
Private Sub unFilterList()
On Error GoTo errLable
Set mCombo.Recordset = mRsOriginalList
Exit Sub
errLable:
If Err.Number = 3061 Then
MsgBox "Will not Filter. Verify Field Name is Correct."
Else
MsgBox Err.Number & " " & Err.Description
End If
End Sub
Public Property Get FilterFieldName() As String
FilterFieldName = mFilterFieldName
End Property
Public Property Let FilterFieldName(ByVal theFieldName As String)
mFilterFieldName = theFieldName
End Property
Private Sub Class_Initialize()
End Sub
Private Sub Class_Terminate()
Set mForm = Nothing
Set mCombo = Nothing
Set mRsOriginalList = Nothing
End Sub
|
|
0
|
|
|
|
Reply
|
EddWood
|
11/18/2009 4:00:03 PM |
|
Do you know the exact line that raises the error? Might it be
Set mRsOriginalList = mCombo.Recordset.Clone
I don't think combo boxes have a Recordset associated with them.
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"EddWood" <Edd_nospam_@/Wood\hotmail.co.uk> wrote in message
news:3A977C42-1B78-40CA-A0D5-169E2A692CE3@microsoft.com...
> Access 2007
>
> I am trying to implement the 'FindAsYouType' example below and each time
> I open the form I get this error message:
>
> "91 Object variable or With block variable not set"
>
> From the information I have applied the changes required, 'myCombo' and
> 'mySearch' field into the form code but cannot see where the problem lies,
> can anyone advise what is wrong
>
> Thanks
>
> FAYTC code >>>>>
>
>
> Option Compare Database
> Option Explicit
>
> 'Class Module Name: FindAsYouTypeCombo
> 'Purpose: Turn any combobox into a "Find As You Type" 'Combobox
> 'Created by: MajP
> 'Demonstrates: OOP, and With Events
> '
> 'Use:To use the class, you need code similar to the 'following in a form's
> module.
> 'Also requires a reference to DAO
> 'Two properties must be set: FilterComboBox
> 'and FilterFieldName. These are the combo box object
> 'and the name of the field that you are filtering.
> '
> '*******Start Form Code*******************
> '
> 'Public faytCombo As FindAsYouTypeCombo
> '
> 'Private Sub Form_Open(Cancel As Integer)
> ' Set faytCombo = New FindAsYouTypeCombo
> ' Set faytCombo.FilterComboBox = Me.myCombo
> ' faytCombo.FilterFieldName = "mySearch"
> 'End Sub
> '
> '******* END Form Code ******************
> '
>
> Private WithEvents mCombo As Access.ComboBox
> Private WithEvents mForm As Access.Form
> Private mFilterFieldName As String
> Private mRsOriginalList As DAO.Recordset
> Public Property Get FilterComboBox() As Access.ComboBox
> Set FilterComboBox = mCombo
> End Property
> Public Property Set FilterComboBox(theFilterComboBox As Access.ComboBox)
> On Error GoTo errLabel
> If Not theFilterComboBox.RowSourceType = "Table/Query" Then
> MsgBox "This class will only work with a combobox that uses a Table or
> Query as the Rowsource"
> Exit Property
> End If
>
> Set mCombo = theFilterComboBox
> Set mForm = theFilterComboBox.Parent
> mForm.OnCurrent = "[Event Procedure]"
> mCombo.OnGotFocus = "[Event Procedure]"
> mCombo.OnChange = "[Event Procedure]"
> mCombo.AfterUpdate = "[Event Procedure]"
> With mCombo
> .SetFocus
> .AutoExpand = False
> End With
> Set mRsOriginalList = mCombo.Recordset.Clone
> Exit Property
> errLabel:
> MsgBox Err.Number & " " & Err.Description
>
> End Property
>
> Private Sub mCombo_Change()
> Call FilterList
> End Sub
> Private Sub mCombo_GotFocus()
> mCombo.Dropdown
> End Sub
> Private Sub mCombo_AfterUpdate()
> Call unFilterList
> End Sub
> Private Sub mForm_Current()
> Call unFilterList
> End Sub
> Private Sub FilterList()
> On Error GoTo errLable
> Dim rsTemp As DAO.Recordset
> Dim strText As String
> Dim strFilter As String
> strText = mCombo.Text
> If mFilterFieldName = "" Then
> MsgBox "Must Supply A FieldName Property to filter list."
> Exit Sub
> End If
> strFilter = mFilterFieldName & " like '" & strText & "*'"
> Set rsTemp = mRsOriginalList.OpenRecordset
> rsTemp.Filter = strFilter
> Set rsTemp = rsTemp.OpenRecordset
> If rsTemp.RecordCount > 0 Then
> Set mCombo.Recordset = rsTemp
> End If
> mCombo.Dropdown
> Exit Sub
> errLable:
> If Err.Number = 3061 Then
> MsgBox "Will not Filter. Verify Field Name is Correct."
> Else
> MsgBox Err.Number & " " & Err.Description
> End If
> End Sub
> Private Sub unFilterList()
> On Error GoTo errLable
> Set mCombo.Recordset = mRsOriginalList
> Exit Sub
> errLable:
> If Err.Number = 3061 Then
> MsgBox "Will not Filter. Verify Field Name is Correct."
> Else
> MsgBox Err.Number & " " & Err.Description
> End If
> End Sub
> Public Property Get FilterFieldName() As String
> FilterFieldName = mFilterFieldName
> End Property
> Public Property Let FilterFieldName(ByVal theFieldName As String)
> mFilterFieldName = theFieldName
> End Property
> Private Sub Class_Initialize()
>
> End Sub
> Private Sub Class_Terminate()
> Set mForm = Nothing
> Set mCombo = Nothing
> Set mRsOriginalList = Nothing
> End Sub
|
|
0
|
|
|
|
Reply
|
Douglas
|
11/18/2009 5:15:50 PM
|
|
"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_gmail.com> wrote in message
news:%23fDoTNHaKHA.5300@TK2MSFTNGP02.phx.gbl...
> Do you know the exact line that raises the error? Might it be
>
> Set mRsOriginalList = mCombo.Recordset.Clone
>
> I don't think combo boxes have a Recordset associated with them.
They do, at least in Access 2003 and later. However, in Access 2003 I find
that the combo's Recordset property returns Nothing unless my code has
already set it to a recordset I created. I don't know how Access 2007
behaves in this regard.
--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html
(please reply to the newsgroup)
|
|
0
|
|
|
|
Reply
|
Dirk
|
11/18/2009 5:45:40 PM
|
|
|
2 Replies
461 Views
(page loaded in 0.061 seconds)
Similiar Articles: error message 91 Object variable or With block variable not set ...Do you know the exact line that raises the error? Might it be Set mRsOriginalList = mCombo.Recordset.Clone I don't think combo boxes have a Recordset associated ... Screen.ActiveControl - error 91 - object variable or with block ...Cannot change combo option - microsoft.public.access.forms ... error message 91 Object variable or With block variable not set ..... into the form code but cannot see ... object variable or with variable not set problem - microsoft ...error message 91 Object variable or With block variable not set ..... form I get this error message: "91 Object variable or With block variable not set ... object ... Object variable not set error - microsoft.public.excel.programming ...Object or class does not support the set of events - microsoft ... error message 91 Object variable or With block variable not set ... Set object variable in class module ... Disabling / customizing error messages - microsoft.public.excel ...error message 91 Object variable or With block variable not set ... Disabling / customizing error messages - microsoft.public.excel ..... messages for two specific error ... Can you look for an image/OLE Object using dlookup - microsoft ...I have tried the following but I keep getting an error message 91 Object variable or With block variable not set (Error 91). Here is what I have tried: Private Sub ... Set object variable in class module - microsoft.public.access ...error message 91 Object variable or With block variable not set ... Set object variable in class module - microsoft.public.access ... error message 91 Object variable or ... winsock - object variable not set - microsoft.public.access ...... get the > > error > > message " Object variableor with block variable not set." ... not set (Error 91) Object variable or With block variable not set (Error 91) See ... Ribbon Invalidate error 91 - microsoft.public.access.modulesdaovba ...... InvalidateControl "cmdNMA" 'Object variable not set (Error 91 ... error message 91 Object variable or With block variable not set ... Ribbon Invalidate error 91 ... run time error '91' - microsoft.public.word.docmanagement ...Run-time error 91, Object Variable or With Block Variable not set "Run-time error 91, Object Variable or With Block Variable not set," error message is encountered if you ... Run-time error 91, Object Variable or With Block Variable not set"Run-time error 91, Object Variable or With Block Variable not set," error message is encountered if you are using Integration Assistant for Excel and the data ... Object variable not set (Error 91) - Microsoft Corporation ...Object variable or With block variable not set (Error 91) See Also Specifics. There are two steps to creating an object variable. First you must declare the object ... Runtime 91, Object Variable or With Block not Set When Exporting ...When generating an FRx report to Excel in FRx, you are getting the message Runtime 91, object variable or with block not set. RESOLUTION In this case, it ... Run-time error 91: Object Variable or With block variable not setI am getting a Run-time error at the end of this code: Public Function GetCanadaAddress(currentAddress As Integer) As CInsideCanadaAddress 'GET ONE ... Runtime Error 91 Fix - How To Resolve The "Object Variable or With ...The error will typically show with this message: "Object Variable or With Block Variable Not Set ... Error 91: Object variable or with block variable not set" The ... 7/27/2012 3:14:14 PM
|
|
|
|
|
|
|
|
|