Newbie: who wants to share some experience?

zeeforel

Registered User.
Local time
Today, 14:14
Joined
Aug 11, 2004
Messages
25
Dear All,

I am trying to "access" three specific tables and some queries in VBA but do not have any clue what code to use. Can someone please share some samples?

The general idea is to fill a database with three tables:
+ Activities: description, date, project, comments
+ Issues: description, date, project, solved?, date solved, solution, comments
+ Network: name person, business unit, experience, phone number

and to write the contents, based on queries or directly from the tables, to a valid txt/html file.


1. How do I access tables or queries, and specific elements in them in VBA?

2. How to write the contents to a file (examples of file writing operations?)


Many thanks.
Best regards,

Marcel
 
You will need to go to Tools->References and find 'Microsoft DAO 3.6' in the list and check it for this:

Number One said:
Dim rst as DAO.Recordset
Dim SQL as String

SQL = "SELECT * FROM tblTestTable"
Set rst = CurrentDB.OpenRecordset(SQL)

Dim strBuffer as string
Dim strLine as string

While Not rst.EOF
strLine = "<html><body><table>"
strLine = strLine & "<tr><td>" & rst("FIELD1") & "</td><td>" & rst("FIELD2") & "</td></tr>" & Chr(13) ' the Chr(13) is a carrage return, keeps the output file somewhat neat and understandable as opposed to one huge line.
strBuffer = strBuffer & strLine
rst.MoveNext
WEnd

Set rst = Nothing

This is sketchy, read up about it.. it has been eons since I've done vb file access, and even longer since VBA~

Number Two said:
Dim fileHandle as Long
fileHandle = FreeFile

Open "c:\myhtml.htm" FOR RANDOM AS fileHandle
PRINT fileHandle, strBuffer
Close fileHandle
 
Thanks, will give it a try!
 

Users who are viewing this thread

Back
Top Bottom