Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

3251 UsingVB6 and Visual Data Manager

Posted on 2002-05-01
6
148 Views
Last Modified: 2010-05-02
Folks,

As part of a project, I was required to enter data into a database created by the VB6 Visual Data Manager.

What is the most striaghtforward way of accessing this using VB6, but not a Data Control.

I've tried ADO, but am getting a 3251 error (suggesting the recordset is readonly), but changing the various options only generates more errors. I'm trying looking at the MS Help - trying is the word.

Speed is of the essence.

Thanks

Mikkil

0
Comment
Question by:Mikkil
  • 3
  • 3
6 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6983184
ADO is the way to go.

Show your code that opens the connection and create the recordset.
0
 

Author Comment

by:Mikkil
ID: 6983285
Emoreau,

Code is :

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Sub dbload()
Set cn = New ADODB.Connection
   
    With cn
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .ConnectionString = "f:\data\p35\vbproj\vbcar\Carins.mdb"
        .Open
    End With
    Set rs = New ADODB.Recordset
    With rs
        .ActiveConnection = cn
        .Source = "Car Insurance Customer Database"
        '.CursorLocation = adUseServer
        '.CursorType = adOpenKeyset
        .Open ' , , , adLockBatchOptimistic
    End With
    With rs
        .MoveFirst
        'Populating field on load of form
        txtpolicy.Text = .Fields(Policy).Value
        txtFirstN.Text = .Fields(Fname).Value
        txtSurn.Text = .Fields(Surname).Value
        CboAddress.Text = .Fields(Address).Value
        txtAge.Text = .Fields(Age).Value
        CboCover.Text = .Fields(Cover).Value
        lblNumr.Caption = rs.RecordCount
    End With
   
End Sub

References are VB for Applications; Runtime objects and procedures; Òbjects and procedures; OLE Automation; Microsoft Access 9.0 Library; Microsoft ActiveX Data Objects 2.5 Library

3251 occurs on rs.open;

Note it also gives Invalid SQL statement on rs.open since; I'm not sure what I've changed to cause this to happen.

Thanks

Mikkil
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 150 total points
ID: 6983327
change your code to:


Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Sub dbload()
Set cn = New ADODB.Connection
   
   cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=f:\data\p35\vbproj\vbcar\Carins.mdb;"

   Set rs = New ADODB.Recordset
   With rs
       .CursorLocation = adUseClient
       .CursorType = adOpenStatic
       .LockType = adLockOptimistic
       .Open "SELECT * FROM CarTable", cn
   End With
   With rs
       .MoveFirst
       'Populating field on load of form
       txtpolicy.Text = .Fields(Policy).Value
       txtFirstN.Text = .Fields(Fname).Value
       txtSurn.Text = .Fields(Surname).Value
       CboAddress.Text = .Fields(Address).Value
       txtAge.Text = .Fields(Age).Value
       CboCover.Text = .Fields(Cover).Value
       lblNumr.Caption = rs.RecordCount
   End With
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Mikkil
ID: 6983433
Emoreau,

Thanks .. that worked.

It's probably naive to ask, but is there a good (i.e. not a Microsoft-type-you-won't-understanding-anything-if-you-don't-already-understand-all-the-Microsoft-terminology) expanation of the whole area of connections / recordsets / source / options thing ?

Mikkil

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6983451
have you check the help for all these methods and properties? You will have some explanations about them.
0
 

Author Comment

by:Mikkil
ID: 6988760
Emoreau,

The point I'm making is that you need to know all the terminology, otherwise you may not find the help you are looking for.

Thanks

Mikkil
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question