updating database value

xxdcmast
04-18-2004, 10:34 PM
I have a value stored as a value in a string in a textboy and a varaible Z. I want to take this new value for Z and update my database with it. I alreayd have declared the connection to my database the Myconn.Open, but when I try to run my prog I get 424 error obeject required.

This is the code I use on the button click

Private Sub Command3_Click()
z = Text6.Text
Text7.Text = z
MyConn.Open
MyConn.Execute ("UPDATE Customers SET Balance = '" & z & "' WHERE Pin = " & x & " and Account = '" & y & "'")
End Sub

wengwashere
04-18-2004, 10:38 PM
Youll have to initialize first the myConn object like this :


dim myConn as ADODB.Connection
SET myConn = new ADODB.Connection


Heres a good site about ADO and the Connection object :

http://www.xtremevbtalk.com/showthread.php?threadid=66994

xxdcmast
04-18-2004, 10:46 PM
I already have the connection dimensioned and have already used that connection to draw the data from the database do I have to redimension it again when ?I want to use it?

wengwashere
04-18-2004, 11:00 PM
I already have the connection dimensioned and have already used that connection to draw the data from the database do I have to redimension it again when ?I want to use it?

If it is already open then you dont need to call


myConn.open


just call the .execute

else, if you have used it, and closed/cleared it somewhere, you need to redimension it and open it again.

xxdcmast
04-19-2004, 11:05 AM
Hmmm tried removing the Myconn.close and still no luck updating to the database. Any other Ideas

MKoslof
04-19-2004, 02:36 PM
Where do you define X and Y?

xxdcmast
04-19-2004, 09:00 PM
Where do you define X and Y?
I define x and y ad the formload and them pass the values of two text boxes into them. Those work fine but for some reason it would let me update the database

MKoslof
04-20-2004, 06:11 AM
Try this...all declarations within the same sub as a test: I am assuming your old value x is an integer based on how you wrote the command string.



Dim cn as ADODB.connection
Dim sSQL as string

sSQL = "UPDATE Customers SET Balance = '" & Text6.Text & "' WHERE Account = '" & Text7.Text & "' AND Pin=" & Text8.Text

Set cn = New ADODB.connection

cn.connectionString = "Your ADO connection String"
cn.Open

cn.Execute sSQL

cn.close
Set cn = Nothing

xxdcmast
04-20-2004, 07:18 AM
Try this...all declarations within the same sub as a test: I am assuming your old value x is an integer based on how you wrote the command string.



Dim cn as ADODB.connection
Dim sSQL as string

sSQL = "UPDATE Customers SET Balance = '" & Text6.Text & "' WHERE Account = '" & Text7.Text & "' AND Pin=" & Text8.Text

Set cn = New ADODB.connection

cn.connectionString = "Your ADO connection String"
cn.Open

cn.Execute sSQL

cn.close
Set cn = Nothing



Once I changed around a few of the textbox names that worked fine... is it that I have to go thru all those steps above each time I want to access the database.

MKoslof
04-20-2004, 07:20 AM
Basically, all you need to do is open the ADO connection (if it is not already open) and then fire your execute command. If you don't close your ADO connection after the command, MAKE SURE before existing the application, or whenever you are finished working with the open connection that you close it and set its variable equal to nothing.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum