Welcome to Dream.In.Code
Become a VB Expert!

Join 149,409 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,196 people online right now. Registration is fast and FREE... Join Now!




Object Variable or WIth Block Not Set

 
Reply to this topicStart new topic

Object Variable or WIth Block Not Set

slscheer
23 Jan, 2008 - 05:49 PM
Post #1

New D.I.C Head
*

Joined: 23 Jan, 2008
Posts: 6

Ok SO i am new to this but I have written a program in which i can add data, with no problems, but when i t comes to a simple update i am just not getting it. FOr this i have created a simple form with two text boxes on it and one command button. The database holds a table called Invoices and the idea is to simply be able to change the amount of the balnce due as money is applied to it. the table has two fields that are important, 1 OrdrNum and 2 Balance I want to be able to update the balance on the record which matchs the orderNum (txtOrderID) with the number entered in the txtRemaining. I keep getting the above error and cant figure it out also i am not sure of the rest of the code Please Help!!

Thanks
Shannon

CODE
Dim intOrderID As Integer
Dim IntBalance As Currency
Dim Myconn As ADODB.Connection
Dim statement As String
Dim conn As New ADODB.Connection

Private Sub cmdSave_Click()

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\TerrysCustomData\TerrysData.mdb'"

conn.Open
statement = " UPDATE Invoices " & _
" SET Balance = '%" & txtRemaining & "%' "
'" WHERE OrdrNum = '%" & txtOrderID & "%'"

Myconn.Execute statement, , adCmdText
Myconn.Close

End Sub

User is offlineProfile CardPM
+Quote Post

Nayana
RE: Object Variable Or WIth Block Not Set
23 Jan, 2008 - 08:51 PM
Post #2

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
On which line of code do you get the error?

I'm guessing it is on Myconn.Execute....

I think the reason is that you have created the variable, but you haven't created the object (with the 'new' keywork).

Why are you using two connections anyway? Are they to the same database? If they are, you should only use the one (conn) connection.
User is offlineProfile CardPM
+Quote Post

slscheer
RE: Object Variable Or WIth Block Not Set
23 Jan, 2008 - 10:28 PM
Post #3

New D.I.C Head
*

Joined: 23 Jan, 2008
Posts: 6

QUOTE(slscheer @ 23 Jan, 2008 - 06:49 PM) *

I made an error when i pasted the code the code had an additional comment ' in front of the WHer statement so i am reposting the attempted code i am using. Also Yes i am getting the error on the Execute line. I am not sure of the actual syntax or placment to SET the NEW object an example would be awesome.

Thanks again !!!

CODE
Dim objserver As clsTerrysDat
Dim rsOrderNum As New ADODB.Recordset
Dim intOrderID As Integer
Dim IntBalance As Currency
Dim Myconn As ADODB.Connection
Dim statement As String
Dim conn As New ADODB.Connection


Private Sub cmdSave_Click()

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\TerrysCustomData\TerrysData.mdb'"

conn.Open
statement = " UPDATE Invoices " & _
" SET Balance = '%" & txtRemaining & "%' " & _
" WHERE OrdrNum = '%" & txtOrderID & "%'"

Myconn.Execute statement, , adCmdText
Myconn.Close

End Sub








User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Object Variable Or WIth Block Not Set
23 Jan, 2008 - 10:47 PM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,476



Thanked: 160 times
Dream Kudos: 9025
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Did his answer solve your problem, all you did was report your original question
User is online!Profile CardPM
+Quote Post

Nayana
RE: Object Variable Or WIth Block Not Set
24 Jan, 2008 - 02:00 AM
Post #5

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
slscheer:

My advice to you is to simply
Don't declare the myconn (get rid of it)

Change the reference from myconn, to just conn.
User is offlineProfile CardPM
+Quote Post

slscheer
RE: Object Variable Or WIth Block Not Set
24 Jan, 2008 - 10:49 AM
Post #6

New D.I.C Head
*

Joined: 23 Jan, 2008
Posts: 6

Hi Everyone who tried to help me with this. It was driving me crazy but I finally figured it out the suggestions help greatly but here is the code that worked

CODE
Option Explicit


'Dim intOrderID As Integer
'Dim intBalance As Currency
'Dim conn As ADODB.Connection
Dim statement As String
Dim conn As New ADODB.Connection


Private Sub cmdSave_Click()

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\TerrysCustomData\TerrysData.mdb'"

conn.Open
statement = " UPDATE Invoices " & _
" SET Balance = " & txtRemaining & " " & _
" WHERE OrdrNum = " & txtOrderID & ""

conn.Execute statement, , adCmdText
conn.Close

End Sub





As you can see i got rid of the myconn references and changed the execute and close staements to reflect this (Thanks Nayana) I also had to remove the single quotes from around the txt(statements) it now works likea charm.

Once again Thank you everyone!!!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 10:38AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month