Solved

Databases and VB - Help needed

Posted on 2002-04-21
7
142 Views
Last Modified: 2010-05-02
Hi, I have a school assignment to do. It has to involve some sort of a database solution.
I've decided to make an address book (i know its been done and overdone). The problem I'm facing is ADO, or what I found to be the only way of using Access databases.
I have been able to make a database and set out the tables and such, yet I am still unaware of how to put data into it, and then read from it.
I've been reading the whole MSDN which the school has, and still cant find much on it.
Can someone point me in the right direction? Perhaps I should use something else - apart from ADO?

Thanx for everything
0
Comment
Question by:romka
7 Comments
 
LVL 3

Expert Comment

by:sridhar_PJ
ID: 6958831
0
 
LVL 6

Expert Comment

by:xSinbad
ID: 6958848
I prefer DAO and would use such as follows.

'To connect and open a table;

Dim RS as recordset
Dim DB as Database
Dim strData

set DB = opendatabase("c:\database.mdb")
set RS = DB.Openrecordset("TableName", VBopenDynaset)

'To move through the recordset

' First Record
RS.MoveFirst

'Next Record
RS.MoveNext

' Add recod to a variable
strData = RS!FieldName

' Change data in field
RS.Edit
RS!FieldName = "Whatever"
RS.Update


'Then to clean up afterwards
set RS = Nothing
set DB = Nothing



I hope that helps you out a little


Cheers
Marcus





0
 
LVL 3

Expert Comment

by:sridhar_PJ
ID: 6958911
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 1

Expert Comment

by:alfanhendro
ID: 6958994
using DAO,if you use MsAccess 2000, you may need to convert your database to previous version.
-open your database
-select tools
     ->database utility
     ->convert database
     ->to prior access database version

Regards
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 200 total points
ID: 6959357
Ok, here is a simple ADO tutorial that you can adapt very easily:

*** Form Code ***

Private cnnAccess As ADODB.Connection
Private rstData As ADODB.Recordset

Private Sub Form_Load()
  'Open Connection
  Set cnnAccess = New ADODB.Connection
  cnnAccess.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\myfolder\mydatabase.mdb;"
  cnnAccess.Open
  'Open Recordset
  Set rstData = New ADODB.Recordset
  rstData.Open "Select * From MyTable",cnnAccess,adOpenStatic,adLockOptimistic
End Sub

Private Sub Form_UnLoad()
  'Close and destroy recordset
  If rstData.State <> adStateClosed Then
    rstData.Close
  End If
  Set rstData = Nothing
  'Close and destroy connection
  If cnnAccess.State <> adStateClosed Then
    cnnAccess.Close
  End If
  Set cnnAccess = Nothing
End Sub

You now have the basics to access your data, you can use the recordset's methods and properties to retrieve/update/insert/delete records.

Private Sub DisplayValues()
  With rstData
    txtField1.Text = .Fields("Field1").Value
    txtField2.Text = .Fields("Field2").Value
  End With
End Sub

Private Sub SaveRecord()
  With rstData
    .Fields("Field1").Value = txtField1.Text
    .Fields("Field2").Value = txtField2.Text
    .Update
  End With
End Sub

Private Sub NewRecord()
  rstData.AddNew
End Sub

And so on.
0
 

Author Comment

by:romka
ID: 6970473
Thank you very much for your help.
It so far has helped my project

Thank you
0
 

Author Comment

by:romka
ID: 6970496
Thank you very much.
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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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