Browse, Open file, assign number on file, and print

  • Thread starter Ricky S. via AccessMonster.com
  • Start date
R

Ricky S. via AccessMonster.com

I have one letter on the shared drive that need to be printed several times
with different sequence numbers each time the letter is printed. I need to
be able to

1. browse and OPEN the letter. (PROBLEM:the browse window opens, but I can’t
bring up the actual letter)
2. print a number (that I have generated in Access) in the bottom left corner
of the letter. Don't know if a bookmark is better or just a print location
will do.
3. and then print the letter.

I need to repeat this operation several times.

- Once the first letter is printed, I don’t need to browse for the letter
again.
- I want to keep the letter open and just print the next number sequence
replaced on the letter
- and then print the letter.

The only thing that is changing is the printed sequence number generated from
Access. This is being used to keep track of the letters sent.

Please help me with this problem. Below is my code.

Private Sub PrintSrv_Click()
'save demographics to table
DoCmd.Save
'browse to find letter

Dim strFilter As String
Dim lngFlags As Long
Dim strFileName As String
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")

Debug.Print Hex(lngFlags)

strInputFileName = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)


'Open a database -
'don't know if I should set the database, since the database may reside
almost anywhere
Set myDataBase = OpenDatabase("C:\Documents\Letters2005.mdb")

'Access the first record from a particular table

Set myActiveRecord = myDataBase.OpenRecordset("Table_1", dbOpenForwardOnly)

'Loop through all the records in the table until the end-of-file marker is
reached

Do While Not myActiveRecord.EOF

'If field #1 contains a non-zero value,
'insert the value of field #2 into the document
'after the current cursor or selection location
'This requires the user to place the cursor somewhere. Can there be a
routine to place it at the bottom of the
'letter without cursor placement?
If myActiveRecord.Fields("Field_1") <> 0 Then
Selection.InsertAfter myActiveRecord.Fields("Field_2")
End If

'access the next record
myActiveRecord.MoveNext

SrvNo = Field_1
RefNo = Field_2
Loop
'saves ref # and count to table
DoCmd.Save

'prints letter with ref # on it
Me!RefNo = NZ(DMax("[Ltrid]", "[qryHome]", "[DateSeq] >= #" & DateSerial(Year
(Date()), Month(Date()), 1)) + 1

'leave word doc open to print next ref# on already open document

'If no more printing
'Then close the database
'myActiveRecord.Close
'myDataBase.Close




End Sub
 
A

Ari

A better way would to be to do this in word. Word can access Access and
select fields from a table and generate multiple copies of a document
based on each record.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top