p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access (http://p2p.wrox.com/forumdisplay.php?f=18)
-   -   How to interact with data using ADO (http://p2p.wrox.com/showthread.php?t=68255)

rohit_ghosh May 21st, 2008 06:06 AM

How to interact with data using ADO
I am trying to send information via my form in access in a table in the same database. I want to do this with ADO but it wont work.

My General Declarations are( The General Declarations are not working):

Dim cnmastertable As ADODB.Connection
Set cnmastertable = CurrentProject.Connection
Dim rslist As ADODB.Recordset
Dim strConnection As String

My Code in the Form_Load event type is:

Private Sub Form_Load()
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Sources=" & CurrentProject.Path & "\List.mdb;"

Set cnmastertable = New ADODB.Connection
cnmastertable.Open strConnection

Set rslist = New ADODB.Recordset

With rslist
    .CursorType = adOpenKeyset
    .CursorLocation = adUseClient
    .LockType = adLockBatchOptimistic
    .Open "tblData", cnmastertable
    .ActiveConnection = Nothing
End With

Set cnmastertable = Nothing

End Sub

I am unable to make the above code work. I do not want to see the existing data in the table tblData. I only want to pass recordset on it based on the records that I type on my form.

The Controls in the form are Name, date and Telephone No.

Please can someone help me rectify my code and also add additional codes to send the data from the controls in the columns in the tblData Table. The tblData Table also has the columns with identical names.

The name of the MDB file is List.mdb
The Form Name is frmList
The name of the table is tblData

Many Thanks,

rohit_ghosh May 21st, 2008 09:11 AM

I Have tried modifying the code to the below stated one. But I am still unable to do it. I am getting a Compile error (Invalis Use of Property) at Set Me.Name = rstblCLMasterData!Name Please can somebody help me.....

Private Sub Form_Load()

Dim rstblData As ADODB.Recordset
Set rstblData = New ADODB.Recordset
With rstblData
    .ActiveConnection = CurrentProject.AccessConnection
    .Source = "Select Name, Name FROM tblData"
    .LockType = adLockReadOnly
    .CursorType = adOpenKeyset
    .CursorLocation = adUseClient
End With
Set Me.Name = rstblCLMasterData!Name
Set rstblData = Nothing

Many Thanks

All times are GMT -4. The time now is 12:22 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.