473,466 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

424 Object Required Error

5 New Member
Hi,

I have below code on Form_Load() , I get one time error when I open this form.

424 Object required, please help ASAP.


Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Private Sub Form_Load()
  3.  
  4. On Error GoTo ThisFormError
  5.  
  6. Dim cnt As ADODB.Connection
  7. Dim rst1 As ADODB.Recordset
  8. Dim stDB As String
  9. Dim stSQL1 As String
  10. Dim stConn As String
  11.  
  12.  
  13.  'Instantiate the ADO-objects.
  14. Set cnt = New ADODB.Connection
  15. Set rst1 = New ADODB.Recordset
  16.  
  17.  'Path to the database.
  18. stDB = "\\server23\abc\db.mdb"
  19.  
  20.  'Create the connectionstring.
  21. stConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
  22. & "Data Source=" & stDB & ";Persist Security Info=False"
  23.  
  24.  
  25. cnt.Open (stConn)
  26. stSQL1 = "SELECT DISTINCT [table 1].[CH#] FROM [table1];"
  27.  
  28.  rst1.Open stSQL1, cnt, adOpenForwardOnly, adLockReadOnly, adCmdText
  29.  
  30.  
  31.         rst1.MoveFirst
  32.     With Me.Cmb_StoreNo
  33.  
  34.         Cmb_StoreNo.AddItem ("All ")
  35.  
  36.          Do While Not rst1.EOF
  37.          Cmb_StoreNo.AddItem rst1![CH#]
  38.          rst1.MoveNext
  39.  
  40.         Loop
  41.  End With
  42.  
  43. ThisFormErrorExit:
  44.         On Error Resume Next
  45.         rst.Close
  46.         Set rst = Nothing
  47.         cnt.Close
  48.         Set cnt = Nothing
  49. ThisFormError:
  50.  MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
  51.  Resume ThisFormErrorExit
  52. End Sub
Nov 7 '08 #1
6 3498
Stewart Ross
2,545 Recognized Expert Moderator Specialist
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

Expand|Select|Wrap|Line Numbers
  1. .AddItem ("All ") 
  2. .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
Nov 7 '08 #2
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command84_Click()
  2. On Error GoTo ThisFormError
  3.  Dim cnt As ADODB.Connection
  4. Dim rst1 As ADODB.Recordset
  5. Dim stDB As String
  6. Dim stSQL1 As String
  7. Dim stConn As String
  8.  
  9. 'Instantiate the ADO-objects.
  10. Set cnt = New ADODB.Connection
  11. Set rst1 = New ADODB.Recordset
  12.  
  13. 'Path to the database.
  14. 'stDB = "\\server23\abc\db.mdb"
  15. stDB = "C:\Ed Herbst\Ed New.mdb"
  16.  
  17.  'Create the connectionstring.
  18. stConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
  19. & "Data Source=" & stDB & ";Persist Security Info=False"
  20.  
  21. cnt.Open (stConn)
  22. stSQL1 = "SELECT DISTINCT [table 1].[CH#] FROM [table1];"
  23.  
  24. rst1.Open stSQL1, cnt, adOpenForwardOnly, adLockReadOnly, adCmdText
  25.  
  26. rst1.MoveFirst
  27.  
  28. With Me.Cmb_StoreNo
  29.   .AddItem ("All ")
  30.     Do While Not rst1.EOF
  31.       Cmb_StoreNo.AddItem rst1![CH#]
  32.       rst1.MoveNext
  33.     Loop
  34. End With
  35.  
  36. ThisFormErrorExit:
  37.   On Error Resume Next
  38.   rst1.Close
  39.   Set rst1 = Nothing
  40.   cnt.Close
  41.   Set cnt = Nothing
  42.     Exit Sub
  43.  
  44. ThisFormError:
  45.   MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
  46.   Resume ThisFormErrorExit
  47. End Sub
Nov 8 '08 #3
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).
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command84_Click()
  2. On Error GoTo ThisFormError
  3.  Dim cnt As ADODB.Connection
  4. Dim rst1 As ADODB.Recordset
  5. Dim stDB As String
  6. Dim stSQL1 As String
  7. Dim stConn As String
  8.  
  9. 'Instantiate the ADO-objects.
  10. Set cnt = New ADODB.Connection
  11. Set rst1 = New ADODB.Recordset
  12.  
  13. 'Path to the database.
  14. 'stDB = "\\server23\abc\db.mdb"
  15. stDB = "C:\Ed Herbst\Ed New.mdb"
  16.  
  17.  'Create the connectionstring.
  18. stConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
  19. & "Data Source=" & stDB & ";Persist Security Info=False"
  20.  
  21. cnt.Open (stConn)
  22. stSQL1 = "SELECT DISTINCT [table 1].[CH#] FROM [table1];"
  23.  
  24. rst1.Open stSQL1, cnt, adOpenForwardOnly, adLockReadOnly, adCmdText
  25.  
  26. rst1.MoveFirst
  27.  
  28. With Me.Cmb_StoreNo
  29.   .AddItem ("All ")
  30.     Do While Not rst1.EOF
  31.       .AddItem rst1![CH#]
  32.       rst1.MoveNext
  33.     Loop
  34. End With
  35.  
  36. ThisFormErrorExit:
  37.   On Error Resume Next
  38.   rst1.Close
  39.   Set rst1 = Nothing
  40.   cnt.Close
  41.   Set cnt = Nothing
  42.     Exit Sub
  43.  
  44. ThisFormError:
  45.   MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
  46.   Resume ThisFormErrorExit
  47. End Sub
Nov 8 '08 #4
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

Expand|Select|Wrap|Line Numbers
  1. .AddItem ("All ") 
  2. .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.
Nov 8 '08 #5
Stewart Ross
2,545 Recognized Expert Moderator Specialist
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
Nov 8 '08 #6
jatin32
5 New Member
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.
Nov 10 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
0
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"...
9
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...
3
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...
0
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...
8
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!!...
1
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...
4
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...
4
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: ...
14
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...
1
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...
0
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...
0
marktang
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,...
0
Oralloy
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,...
1
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...
0
tracyyun
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...
0
agi2029
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,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.