MS Access to VB program (or Excel) using VB code

  Charence 00:35 26 Jun 2004
Locked

Hi,

At the moment all I have managed is to open a database using Visual Basic code, but not extract data from it.

Could anybody please tell me what VB code I would need to open a database and place it in a program I have written?

Thanks

Charence

  AccessMoron 13:07 26 Jun 2004

what version of access, VB or Excel are u using?

  Charence 19:16 26 Jun 2004

Access 2002, VB6, Excel 2002

Cheers, Charence

  Charence 23:38 26 Jun 2004

I have managed to open the database using VB but cannot extract data from it. Any ideas?

Here's the code that opens it

Dim db As Object

Private Sub Workbook_Open()

Set db=GetObject("database.mdb")

******

Thanks

  Charence 12:37 29 Jun 2004

any ideas anybody?

Thanks

  Charence 18:22 29 Jun 2004

Question Rephrased

**************************************

What Visual Basic Code would I need to write in order to view data in tables within Access Database?

**************************************

Thanks

  VoG II 18:26 29 Jun 2004

Does click here help?

  AccessMoron 23:36 03 Jul 2004

put the microsoft ADO data control onto the form, right click its properties (this will get u the connection string)

then in the code window you need the following

code that follows has not been tested. nut its somewhere pretty close.


dim DB as adodb.database
dim RS as adodb.recordset

set db = new adodb.database
db.connectionstring = {get this from the ado control}
db.open

set rs = new adodb.recordset
rs.activeconnection = db
rs.open {SQL string}

if not rs.eof and not rs.bof then
msgbox rs.fields("myFieldName").value
end if

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Alienware 17 R4 2017 review

These brilliant Lego posters show just what children's imaginations are capable of

Mac power user tips and hidden tricks

Comment réinitialiser votre PC, ordinateur portable ou tablette Windows ?