Hello. I have an Access database with one table containing user data; one record per user. One of the table fields is FullName.
In Word, I have a template called Filler.dot, where I store several macros. This template opens automatically when Word opens, so the macros are always available.
In this Filler.dot, I created a form which gives me three options, letter, fax, and memo. I open the form by running the LMF macro, which reads:
The form has a listbox listing all the records from the Access database, FullName field. The listbox is pulling all records as desired.
The code I wrote to open the form and connect to the database is:
My objective is to select a type of correspondence (letter, memo, or fax), click a name in the listbox, then and click a cmdGenerate button, which will run some (currently non-existent) code to open the right type of document and insert fields from the record I selected in the listbox.
Where I'm stuck is:
1. Narrowing down the table to the record selected in the listbox.
2. Inserting the data from the table fields into the document I just opened (letter, memo or fax) which has pre-entered text and it's just waiting for me to fill out the rest of the information with data from the database table, selected record.
I think I have to create bookmarks in the correspondence document as placeholders to where I want the fields from the database to be entered.
I looked in the FAQs and searched, but couldn't find any snipets that would give me a clue I can follow.
I hope I have explained sufficiently, but please ask away and I'll try to clarify wherever I went coo coo.
In Word, I have a template called Filler.dot, where I store several macros. This template opens automatically when Word opens, so the macros are always available.
In this Filler.dot, I created a form which gives me three options, letter, fax, and memo. I open the form by running the LMF macro, which reads:
Code:
Sub LMF()
frmTemplateFiller.Show
End Sub
The form has a listbox listing all the records from the Access database, FullName field. The listbox is pulling all records as desired.
The code I wrote to open the form and connect to the database is:
Code:
Public Sub UserForm_Activate()
Dim strSQL As String
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Me\My Documents\Users\TemplateFiller.accdb;Persist Security Info=False"
strSQL = "SELECT * FROM tblUsers"
rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly
' populate the list box
Do While Not rs.EOF
lstUsers.AddItem rs!FullName
rs.MoveNext
Loop
End Sub
My objective is to select a type of correspondence (letter, memo, or fax), click a name in the listbox, then and click a cmdGenerate button, which will run some (currently non-existent) code to open the right type of document and insert fields from the record I selected in the listbox.
Where I'm stuck is:
1. Narrowing down the table to the record selected in the listbox.
2. Inserting the data from the table fields into the document I just opened (letter, memo or fax) which has pre-entered text and it's just waiting for me to fill out the rest of the information with data from the database table, selected record.
I think I have to create bookmarks in the correspondence document as placeholders to where I want the fields from the database to be entered.
I looked in the FAQs and searched, but couldn't find any snipets that would give me a clue I can follow.
I hope I have explained sufficiently, but please ask away and I'll try to clarify wherever I went coo coo.