View Full Version : VB6 Update Record with ADO Controller


Ripley
11-09-2007, 08:08 AM
Hey guys.

I need to be able to update a record when i click a command button.

I've figured the best way to do this is with the use of an update query.

How would i go about this?

Perhaps set a control such as Dim ADOUpdate As ADODB.Command, set the ActiveConnection to the current connection, the CommandText would clearly be the sql i want to run, and the CommandType is text.

I cant figure out how to do it. Any ideas?:rolleyes:

DCrake
02-22-2008, 07:43 AM
First make sure you have ADODB referenced in your project

Next
declare the following in your start up Declarations

Public MasterDbConn As New ADODB.Connection


In your Statup Module

MasterDbConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyMdb & ";"

MasterDbConn.CursorLocation = adUseClient

Where MyMdb is the path and name of your MDB


To use the mdb in your code use the following

Dim Tbl As New ADODB.Recordset
Set Tbl = New ADODB.Recordset
With Tbl
.Open "YourTableName", MasterDbConn, adOpenKeyset, adLockOptimistic, adCmdTable


Or


Dim rs As New ADODB.Recordset

With MasterDbConn
rs.Open "SELECT * FROM TblLoginSessions WHERE fldUserName ='" & WhoAmi & "'And fldOrganisation ='" & szOrgCode & "' ORDER BY fldLoginKey DESC ", MasterDbConn, adOpenStatic, adLockReadOnly, adCmdText

If Not rs.EOF And Not rs.BOF Then
.....
End If

rs.Close

Set rs = Nothing


The above is snapshots of my code and the table names and critieria is defined by yourself.


Code Master::cool:http://www.icraftlimited.co.uk