Solved

Databases and VB - Help needed

Posted on 2002-04-21
7
143 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Title # Comments Views Activity
VBA filters 2 70
VBA: Personal Macro Retain/Highlight/Remove values in a selected column 4 35
Help me. 3 68
Create Files based on Cell Values in a Range in Excel 12 43
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

679 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