I have a form in Access that needs to move specific information to Word. I was able to get it to work in some respects, but I just hit a bump. I thought I tested it, but now it isn't working.
The script is below, but here is what is happening. I have multiple buttons using cmdPrint to send to multiple Word Documents. Each button sends information from the line it sits next to including combobox info and text box info.
I am trying to show and argument where by if a selection is used on the line then open this document elseif this selection is used then open this document.
For some reason the first line keeps the initial used information then if you click on another button it opens the document in that corresponds to that button, but it opens it using the criteria used in the first buttons line. For example Button 1, Button 1.1 --- There is info in boxes next to Button 1 from a previous entering. I Click Button 1.1 and it opens Document 1.1, but uses the info that was selected next to Button 1 not the new info next to Button 1.1.
Sorry if it sounds confusing. I tried If and If Else If, but nothing seems to work.
THanks for any help.
Here is the script for Button 1:
The script is below, but here is what is happening. I have multiple buttons using cmdPrint to send to multiple Word Documents. Each button sends information from the line it sits next to including combobox info and text box info.
I am trying to show and argument where by if a selection is used on the line then open this document elseif this selection is used then open this document.
For some reason the first line keeps the initial used information then if you click on another button it opens the document in that corresponds to that button, but it opens it using the criteria used in the first buttons line. For example Button 1, Button 1.1 --- There is info in boxes next to Button 1 from a previous entering. I Click Button 1.1 and it opens Document 1.1, but uses the info that was selected next to Button 1 not the new info next to Button 1.1.
Sorry if it sounds confusing. I tried If and If Else If, but nothing seems to work.
THanks for any help.
Here is the script for Button 1:
Code:
Private Sub cmdPrint_1_Click()
'Print customer slip for current customer.
Dim appWord As Word.Application
Dim doc As Word.Document
'Avoid error 429, when Word isn’t open.
On Error Resume Next
Err.Clear
'Set appWord object variable to running instance of Word.
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn’t open, create a new instance of Word.
Set appWord = New Word.Application
End If
If Disposition = "Guilty" And DrivingClass = "4-hour Defensive" Then
Set doc = appWord.Documents.Open("C:\Clients\Guilty4hrFee1.docx", , True)
With doc
.FormFields("fldLastName").Result = Me!LastName
.FormFields("fldFirstName").Result = Me!FirstName
.FormFields("fldLastName1").Result = Me!LastName
.FormFields("fldFirstName1").Result = Me!FirstName
.FormFields("fldAddress1").Result = Me!Address1
.FormFields("fldAddress2").Result = Me!Address2
.FormFields("fldCity").Result = Me!City
.FormFields("fldState").Result = Me!State
.FormFields("fldZip").Result = Me!Zip
.FormFields("fldTicketNumber").Result = Me!TicketNumber
.FormFields("fldCounty").Result = Me!County
.FormFields("fldPayDate").Result = Me!DueDate
.FormFields("fldFine").Result = Me!Fine
.Visible = True
.Activate
End With
End If
If Disposition = "Guilty" And DrivingClass = "8-hour Aggressive" Then
Set doc = appWord.Documents.Open("C:\Clients\Guilty8hrFee1.docx", , True)
With doc
.FormFields("fldLastName").Result = Me!LastName
.FormFields("fldFirstName").Result = Me!FirstName
.FormFields("fldLastName1").Result = Me!LastName
.FormFields("fldFirstName1").Result = Me!FirstName
.FormFields("fldAddress1").Result = Me!Address1
.FormFields("fldAddress2").Result = Me!Address2
.FormFields("fldCity").Result = Me!City
.FormFields("fldState").Result = Me!State
.FormFields("fldZip").Result = Me!Zip
.FormFields("fldTicketNumber").Result = Me!TicketNumber
.FormFields("fldCounty").Result = Me!County
.FormFields("fldPayDate").Result = Me!DueDate
.FormFields("fldFine").Result = Me!Fine
.Visible = True
.Activate
End With
End If
If Disposition = "DISMISSED" And DrivingClass = "" Then
Set doc = appWord.Documents.Open("C:\Clients\DismissedLetter1.docx", , True)
With doc
.FormFields("fldLastName").Result = Me!LastName
.FormFields("fldFirstName").Result = Me!FirstName
.FormFields("fldLastName1").Result = Me!LastName
.FormFields("fldFirstName1").Result = Me!FirstName
.FormFields("fldAddress1").Result = Me!Address1
.FormFields("fldAddress2").Result = Me!Address2
.FormFields("fldCity").Result = Me!City
.FormFields("fldState").Result = Me!State
.FormFields("fldZip").Result = Me!Zip
.FormFields("fldTicketNumber").Result = Me!TicketNumber
.FormFields("fldCounty").Result = Me!County
.FormFields("fldPayDate").Result = Me!DueDate
.FormFields("fldFine").Result = Me!Fine
.Visible = True
.Activate
End With
End If
If Disposition = "NOT adjud NO points" And DrivingClass = "" Then
Set doc = appWord.Documents.Open("C:\Clients\NoNotFee1.docx", , True)
With doc
.FormFields("fldLastName").Result = Me!LastName
.FormFields("fldFirstName").Result = Me!FirstName
.FormFields("fldLastName1").Result = Me!LastName
.FormFields("fldFirstName1").Result = Me!FirstName
.FormFields("fldAddress1").Result = Me!Address1
.FormFields("fldAddress2").Result = Me!Address2
.FormFields("fldCity").Result = Me!City
.FormFields("fldState").Result = Me!State
.FormFields("fldZip").Result = Me!Zip
.FormFields("fldTicketNumber").Result = Me!TicketNumber
.FormFields("fldCounty").Result = Me!County
.FormFields("fldPayDate").Result = Me!DueDate
.FormFields("fldFine").Result = Me!Fine
.Visible = True
.Activate
End With
End If
If Disposition = "NOT adjud NO points" And DrivingClass = "4-hour Defensive" Then
Set doc = appWord.Documents.Open("C:\Clients\NoNot4hrFee1.docx", , True)
With doc
.FormFields("fldLastName").Result = Me!LastName
.FormFields("fldFirstName").Result = Me!FirstName
.FormFields("fldLastName1").Result = Me!LastName
.FormFields("fldFirstName1").Result = Me!FirstName
.FormFields("fldAddress1").Result = Me!Address1
.FormFields("fldAddress2").Result = Me!Address2
.FormFields("fldCity").Result = Me!City
.FormFields("fldState").Result = Me!State
.FormFields("fldZip").Result = Me!Zip
.FormFields("fldTicketNumber").Result = Me!TicketNumber
.FormFields("fldCounty").Result = Me!County
.FormFields("fldPayDate").Result = Me!DueDate
.FormFields("fldFine").Result = Me!Fine
.Visible = True
.Activate
End With
End If
If Disposition = "NOT adjud NO points" And DrivingClass = "8-hour Aggressive" Then
Set doc = appWord.Documents.Open("C:\Clients\NoNot8hrFee1.docx", , True)
With doc
.FormFields("fldLastName").Result = Me!LastName
.FormFields("fldFirstName").Result = Me!FirstName
.FormFields("fldLastName1").Result = Me!LastName
.FormFields("fldFirstName1").Result = Me!FirstName
.FormFields("fldAddress1").Result = Me!Address1
.FormFields("fldAddress2").Result = Me!Address2
.FormFields("fldCity").Result = Me!City
.FormFields("fldState").Result = Me!State
.FormFields("fldZip").Result = Me!Zip
.FormFields("fldTicketNumber").Result = Me!TicketNumber
.FormFields("fldCounty").Result = Me!County
.FormFields("fldPayDate").Result = Me!DueDate
.FormFields("fldFine").Result = Me!Fine
.Visible = True
.Activate
End With
End If
Set rst = Nothing
Set doc = Nothing
Set appWord = Nothing
Exit Sub
ErrorHandler:
MsgBox Err & Err.Description
End Sub
Last edited: