Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging Records

Status
Not open for further replies.

PDriggers

Technical User
May 11, 2004
1
US
I have created a database. I wish to merge some of the information into either a word document, or a report. However, I only wish to merge one record at a time, via a command button.

For example, you could enter the information for the contact then click on one of four buttons to print the specific report, or merge the data to a word document for that individual ONLY.

Is there a way I can do this?

In case you hadn't gathered, I am not at all "Access Smart" and am running along by the seat of my pants so to speak, so please speak at a nice "low level" of technical jargon.

Thank you in anticipation.
 
Yes.

You could query your main table based on what the user enters and display that record in a report and export it to Word. But this could present a problem if the users are not entering data for the key field (the field that uniquely identifies each record) of your tables. For example if you have 3 people named Smith it would return all 3 Smiths, but if you enter the value that uniquely identifies that record it will only display that record.

You could also create a temp table based on the data the user enters, open a report that has the temp table as its recordsource, then use the OutputTo function to output the report to Word.

Note, each time you use the latter method you would need to purge the temp table. Otherwise it will keep growing by 1 each time you runit.

Hope this helps.
 
I have something similar that I'm doing in one of my dbs.

Firstly created you're word doc and where you want the data to be inserted create a bookmark with an appropiate name. Continue with as many bookmarks as you like.

In your access app ad a button open the word doc and send the info puting it the right bookmark. Here's some code to get you started. I use it to generate contracts.
--------------------------------------

Private Sub btnMerge_Click()
On Error GoTo Err_btnMerge_Click

Dim objWord As Word.Application
Dim tmpInitCopy As Long
Dim tmpAccess As String
Dim tmpWeight As Integer
Dim tmpCopies As Long
Dim tmpMainDoc As String
Dim intW As Integer

intW = 1

If Me!StartCount <= 0 Then
tmpInitCopy = InputBox("Please enter the initial meter reading", "Initial Reading", 0)
Me!StartCount = tmpInitCopy
Else
tmpInitCopy = Me!StartCount
End If

tmpWeight = nnz(DLookup("[TonerWeight]", "tblmodelDetails", "[Model]=" & "'" & Forms!frmclientUnits!Model & "'"))
tmpCopies = nnz(DLookup("[CopyPerToner]", "tblmodelDetails", "[Model]=" & "'" & Forms!frmclientUnits!Model & "'"))
tmpAccess = GetAccessory(UnitID)

Set objWord = CreateObject("Word.Application")

With objWord
'Make the application visible.
.Visible = True

'Open the document.
.Documents.Open ("C:\SomeDoc")

' needed to allow word to open up on slow PCs
For intW = 1 To 10000
DoEvents
Next intW

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("StartDate").Select
.Selection.Text = (CStr(Forms!frmContractDetails!StartDate))
.ActiveDocument.Bookmarks("Name").Select
.Selection.Text = (CStr(UCase(ntz(Forms!company!Name))))
.ActiveDocument.Bookmarks("Address").Select
.Selection.Text = (CStr(UCase(ntz(Forms!company!Address1) & " " & ntz(Forms!company!Address2) & ", " & ntz(Forms!company!Suburb) & ", " & ntz(Forms!company!State) & " " & ntz(Forms!company!PostCode))))
.ActiveDocument.Bookmarks("MakeModel").Select
.Selection.Text = (CStr(UCase(ntz(Forms!frmclientUnits!Make) & " " & ntz(Forms!frmclientUnits!Model))))
.ActiveDocument.Bookmarks("SerialNo").Select
.Selection.Text = (CStr(UCase(ntz(Forms!frmclientUnits!SerialNo))))
.ActiveDocument.Bookmarks("Initial").Select
.Selection.Text = (CStr(tmpInitCopy))
.ActiveDocument.Bookmarks("Rate").Select
If Forms!frmContractDetails!MonthCharge <= 0 Then
.Selection.Text = (CStr("0.00"))
Else
.Selection.Text = (CStr(Forms!frmContractDetails!MonthCharge))
End If
.ActiveDocument.Bookmarks("RateCopies").Select
.Selection.Text = (CStr(Forms!frmContractDetails!CopiesMonth))
.ActiveDocument.Bookmarks("Location").Select
.Selection.Text = (CStr(UCase(ntz(Forms!frmclientUnits!Location))))
.ActiveDocument.Bookmarks("Excess").Select
.Selection.Text = (CStr(Forms!frmContractDetails!XSRate))
.ActiveDocument.Bookmarks("Contact").Select
.Selection.Text = (CStr(ntz(Forms!frmclientUnits!UContact)))
.ActiveDocument.Bookmarks("Phone").Select
.Selection.Text = (CStr(ntz(Forms!frmclientUnits!UPhone)))
.ActiveDocument.Bookmarks("Accessories").Select
.Selection.Text = (CStr(UCase(tmpAccess)))
.ActiveDocument.Bookmarks("Extra").Select
If Forms!frmContractDetails!ContractExtraRate <= 0 Then
.Selection.Text = (CStr("0.00"))
Else
.Selection.Text = (CStr(Format(Forms!frmContractDetails!ContractExtraRate, "#,##0.00")))
End If
.ActiveDocument.Bookmarks("Weight").Select
.Selection.Text = (CStr(tmpWeight))
.ActiveDocument.Bookmarks("TonerCopies").Select
.Selection.Text = (CStr(tmpCopies))

End With

'Print the document in the foreground so Microsoft Word will not close
'until the document finishes printing.
objWord.ActiveDocument.PrintOut Background:=False

'Close the document without saving changes.
objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

'Quit Microsoft Word and release the object variable.
objWord.Quit
Set objWord = Nothing

Me!ContLastUpdate = Date

Exit Sub

Exit_btnMerge_Click:
Exit Sub

Err_btnMerge_Click:
If Err.Number = 94 Then
objWord.Selection = ""
Resume Next
ElseIf Err.Number = 2046 Then
MsgBox "Message"
ElseIf Err.Number = 5941 Then
Err.Clear
Resume
Else
MsgBox Err.Number & vbCr & Err.Description
End If
Exit Sub

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top