|
-
Oct 5th, 2005, 11:49 PM
#1
Thread Starter
Junior Member
Word, VBA and a Database
Hi Guys,
I need to be able to use VBA to connect to a Microsoft Access Database, use SQL to query my database and insert values at bookmarks all within a Microsoft Word Document.
I am sure it can be done but need some information on the references and code etc... I know how to do it in ASP but can't figure this VBA out. I know how to place values into the word document etc using VBA, just not the databse connection etc...
Thanks
Shane
-
Oct 6th, 2005, 03:40 AM
#2
Hyperactive Member
Re: Word, VBA and a Database
Hi,
This is the way normally i use to connect to my database.
Hope it helps u..
VB Code:
Dim w As Workspace
Dim w As Workspace
Dim db As Database
Dim rst As Recordset
Set w = DBEngine.Workspaces(0)
Set db = w.OpenDatabase("c:\mis.mde")
Set rst = db.OpenRecordset("tbl_months")
If Not rst.RecordCount = 0 Then
MsgBox rst.RecordCount
End If
*****You need to refer Microsoft DAO for this in u r VBA..
All the best
Thanx & Regards
Anu.
The Difference between a Successful person and others is not a Lack of Knowledge,
But rather a Lack of WILL 
-
Oct 6th, 2005, 08:45 AM
#3
Thread Starter
Junior Member
Re: Word, VBA and a Database
Ok... once I have that... how would I use SQL to query the table, and return a particular record set etc so I can then put particular fields of my record into particular places on my document.
-
Oct 6th, 2005, 12:06 PM
#4
Frenzied Member
Re: Word, VBA and a Database
The bookmarks in your document I don't know, but instead of opening a table you could open your query in the recordset:
Set rst = db.OpenRecordset("SELECT fldFoo FROM tblBar WHERE fldFoo = 'Holy Cow'")
Tengo mas preguntas que contestas
-
Oct 6th, 2005, 08:46 PM
#5
Thread Starter
Junior Member
Re: Word, VBA and a Database
How can you specify the databse password when you connect to your database? IE: my access database has a password set on it.
-
Oct 6th, 2005, 11:15 PM
#6
Hyperactive Member
Re: Word, VBA and a Database
Chk it out ....this will helps u...
VB Code:
Set db = w.OpenDatabase("c:\db11.mdb", False, False, "MS Access;PWD=123")
change u r password over here and place the same in ur code..
Im sure ...It will works...
All the best..
Thanx & Regards
Anu..
(Please rate the post if it works 4 u...)
The Difference between a Successful person and others is not a Lack of Knowledge,
But rather a Lack of WILL 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|