Hi,
I have below code on Form_Load() , I get one time error when I open this form.
424 Object required, please help ASAP. - Option Compare Database
-
Private Sub Form_Load()
-
-
On Error GoTo ThisFormError
-
-
Dim cnt As ADODB.Connection
-
Dim rst1 As ADODB.Recordset
-
Dim stDB As String
-
Dim stSQL1 As String
-
Dim stConn As String
-
-
-
'Instantiate the ADO-objects.
-
Set cnt = New ADODB.Connection
-
Set rst1 = New ADODB.Recordset
-
-
'Path to the database.
-
stDB = "\\server23\abc\db.mdb"
-
-
'Create the connectionstring.
-
stConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
-
& "Data Source=" & stDB & ";Persist Security Info=False"
-
-
-
cnt.Open (stConn)
-
stSQL1 = "SELECT DISTINCT [table 1].[CH#] FROM [table1];"
-
-
rst1.Open stSQL1, cnt, adOpenForwardOnly, adLockReadOnly, adCmdText
-
-
-
rst1.MoveFirst
-
With Me.Cmb_StoreNo
-
-
Cmb_StoreNo.AddItem ("All ")
-
-
Do While Not rst1.EOF
-
Cmb_StoreNo.AddItem rst1![CH#]
-
rst1.MoveNext
-
-
Loop
-
End With
-
-
ThisFormErrorExit:
-
On Error Resume Next
-
rst.Close
-
Set rst = Nothing
-
cnt.Close
-
Set cnt = Nothing
-
ThisFormError:
-
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
-
Resume ThisFormErrorExit
-
End Sub
6 3498
Hi. I have added code tags to your code, which give line numbers that make it easier to refer to specific lines.
It would have helped us if you had advised where in your code your object error is arising. Otherwise we are guessing. Informed guesswork, but still guessing.
I'd suggest looking at what follows the With statement in line 32. If you wish to refer to your combo properties you need to use the dot notation to do so - which you are not doing (lines 34 and 37). As you already specified the name of the combo in line 32 you do not need to repeat this. Instead the syntax for lines 34 and 37 should be - .AddItem ("All ")
-
.AddItem rst1![CH#]
As I said this is a guess at present - your error could be occurring before this point for all I know - but your syntax is definitely in error here.
-Stewart
ADezii 8,834
Recognized Expert Expert
In your code block, modify Lines 34, 37, 45, and 46, then add Line XX. The corrected code is posted below for your convenience: - Private Sub Command84_Click()
-
On Error GoTo ThisFormError
-
Dim cnt As ADODB.Connection
-
Dim rst1 As ADODB.Recordset
-
Dim stDB As String
-
Dim stSQL1 As String
-
Dim stConn As String
-
-
'Instantiate the ADO-objects.
-
Set cnt = New ADODB.Connection
-
Set rst1 = New ADODB.Recordset
-
-
'Path to the database.
-
'stDB = "\\server23\abc\db.mdb"
-
stDB = "C:\Ed Herbst\Ed New.mdb"
-
-
'Create the connectionstring.
-
stConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
-
& "Data Source=" & stDB & ";Persist Security Info=False"
-
-
cnt.Open (stConn)
-
stSQL1 = "SELECT DISTINCT [table 1].[CH#] FROM [table1];"
-
-
rst1.Open stSQL1, cnt, adOpenForwardOnly, adLockReadOnly, adCmdText
-
-
rst1.MoveFirst
-
-
With Me.Cmb_StoreNo
-
.AddItem ("All ")
-
Do While Not rst1.EOF
-
Cmb_StoreNo.AddItem rst1![CH#]
-
rst1.MoveNext
-
Loop
-
End With
-
-
ThisFormErrorExit:
-
On Error Resume Next
-
rst1.Close
-
Set rst1 = Nothing
-
cnt.Close
-
Set cnt = Nothing
-
Exit Sub
-
-
ThisFormError:
-
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
-
Resume ThisFormErrorExit
-
End Sub
ADezii 8,834
Recognized Expert Expert
In your code block, modify Lines 34, 37, 45, and 46, then add Line 42 in the corrected code block. The corrected code is posted below for your convenience, and the corrected lines in the revised code are: 29, 31, 38, and 39. There was never a rst Recordset in the 1st place, so you could never close it, ergo the Object Required Error. You must also Exit the Routine prior to the Msgbox Line (added Line 42). - Private Sub Command84_Click()
-
On Error GoTo ThisFormError
-
Dim cnt As ADODB.Connection
-
Dim rst1 As ADODB.Recordset
-
Dim stDB As String
-
Dim stSQL1 As String
-
Dim stConn As String
-
-
'Instantiate the ADO-objects.
-
Set cnt = New ADODB.Connection
-
Set rst1 = New ADODB.Recordset
-
-
'Path to the database.
-
'stDB = "\\server23\abc\db.mdb"
-
stDB = "C:\Ed Herbst\Ed New.mdb"
-
-
'Create the connectionstring.
-
stConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
-
& "Data Source=" & stDB & ";Persist Security Info=False"
-
-
cnt.Open (stConn)
-
stSQL1 = "SELECT DISTINCT [table 1].[CH#] FROM [table1];"
-
-
rst1.Open stSQL1, cnt, adOpenForwardOnly, adLockReadOnly, adCmdText
-
-
rst1.MoveFirst
-
-
With Me.Cmb_StoreNo
-
.AddItem ("All ")
-
Do While Not rst1.EOF
-
.AddItem rst1![CH#]
-
rst1.MoveNext
-
Loop
-
End With
-
-
ThisFormErrorExit:
-
On Error Resume Next
-
rst1.Close
-
Set rst1 = Nothing
-
cnt.Close
-
Set cnt = Nothing
-
Exit Sub
-
-
ThisFormError:
-
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
-
Resume ThisFormErrorExit
-
End Sub
ADezii 8,834
Recognized Expert Expert
Hi. I have added code tags to your code, which give line numbers that make it easier to refer to specific lines.
It would have helped us if you had advised where in your code your object error is arising. Otherwise we are guessing. Informed guesswork, but still guessing.
I'd suggest looking at what follows the With statement in line 32. If you wish to refer to your combo properties you need to use the dot notation to do so - which you are not doing (lines 34 and 37). As you already specified the name of the combo in line 32 you do not need to repeat this. Instead the syntax for lines 34 and 37 should be - .AddItem ("All ")
-
.AddItem rst1![CH#]
As I said this is a guess at present - your error could be occurring before this point for all I know - but your syntax is definitely in error here.
-Stewart
Hello Stewart! The code segment that you are referring to, although not generally an accepted format, is still nonetheless fully functional. Just some useless information. Take care.
Thanks for the clarification ADezii.
@ Jatin32 I do wish you had let us know where in your code the original error was occurring, as it would have avoided looking at other lines in the code which although non-standard (and indeed not requiring a WITH statement to work) were not the source of the problem.
-S
Thanks for the clarification ADezii.
@ Jatin32 I do wish you had let us know where in your code the original error was occurring, as it would have avoided looking at other lines in the code which although non-standard (and indeed not requiring a WITH statement to work) were not the source of the problem.
-S
This error did not give me any line number.
I have commented out 'On error line and it worked. I have not tried this posted code yet, but I will try it out and let you know.
Thanks a lot guys, appreciated.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dave Hammond |
last post by:
I've got what should be a simple assignment of either an element value
or a default string to a variable, but when the element doesn't exist I
get an "Object required" error rather than an...
|
by: muralidharan |
last post by:
WebForm1.aspx Code:
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI"
Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView
id="TreeView1" Height="520"...
|
by: Remulac |
last post by:
Hello,
I'm trying to get the value out of a dropdown list box and
assign it to a variable. When I click on the list box, I
invoke this line of code. I get the error, "Object
reference not set...
|
by: Adriano |
last post by:
Hello,
when I try to print something, either DataGrid or from Crystal Report viever
the folowing error message appears and cancels printing:
Object reference not set to an instance of an...
|
by: Deepak C.G via .NET 247 |
last post by:
I want to dispose the image object in my child form, unless I won't dispose this
object i can't delete the image file in my folder.
I get this error in MDIparent form
"An unhandled exception...
|
by: ST |
last post by:
Hello everyone, Can anyone help me with this error above when I debug my web
app project in vstudio.net?? I can't figure it out! It was working fine for
months, and now all of a sudden it's not!!...
|
by: Don |
last post by:
I'm getting the following exception displayed in the task list at design
time for my project:
"Code generation for property 'Controls' failed. Error was: 'Object
reference not set to an...
|
by: ink |
last post by:
Hi All
I am relatively new to doing this and i think that i am making some king of
school boy error.
The error i am getting is on the following line of code.
XmlSerializer xs = new...
|
by: livmacca |
last post by:
Hi,
I am new to VB .Net programming and is trying to create a webpage. I encountered the following error and is totally clueless on how to make it work:
...
|
by: chromis |
last post by:
Hi,
I've been trying to implement a more OOP oriented approach to dealing with user security on one of my websites, and I am trying to validate the user against an array of roles, however I am...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |