AWAISKAZMI
Registered User.
- Local time
- Today, 08:29
- Joined
- Oct 28, 2017
- Messages
- 12
When i use this code i get error "Object Required"
Private Sub Command12_Click()
Dim cn As ADODB.Connection
Set rs = New ADODB.Recordset
On Error GoTo errorhandler
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
rs.ActiveConnection = CurrentProject.Connection
rs.Open ("select * from MySelectedObservations")
Dim objWord As Word.Application
Dim pathgetter As String
Dim doc As Word.Document
Dim WordHeaderFooter As HeaderFooter
Dim filepath As String
Set objWord = CreateObject("Word.Application")
pathgetter = DLookup("Word_Path_Field", "WORD_PATH_TBL", "Serial = 1")
filepath = "" & pathgetter & "\Observations " & Format(Now(), "dd-mm-yyyy") & ".docx"
With objWord
.Visible = True
Set doc = .Documents.Open(filepath)
End With
With objWord.Selection
.Font.Name = "Times New Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = True
.Font.Underline = wdUnderlineSingle
'.Font.Bold = True
.TypeText Observation_Heading.Value
.TypeText ":"
.TypeParagraph
.Font.Name = "Times New Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = False
.Font.Underline = wdUnderlineNone
.TypeText Observation_Details.Value
.TypeParagraph
.TypeParagraph
.Font.Name = "Times New Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = True
.Font.Underline = wdUnderlineNone
.TypeText "Risk Implication: "
.Font.Name = "Times New Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = False
.Font.Underline = wdUnderlineNone
.TypeText Risk_Implication.Value
.TypeParagraph
.Font.Name = "Times new Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = True
.Font.Underline = wdUnderlineNone
.TypeText "Risk Category: "
.TypeParagraph
.Font.Name = "Times New Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = False
.Font.Underline = wdUnderlineNone
.TypeText Risk_Category.Value
.TypeParagraph
.Font.Name = "Times New Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = True
.Font.Underline = wdUnderlineNone
.TypeText "Branch Remarks: "
.TypeParagraph
.TypeParagraph
End With
doc.Save
doc.Activate
errorhandler:
MsgBox Err.Description
End Sub
Can anybody help me
Private Sub Command12_Click()
Dim cn As ADODB.Connection
Set rs = New ADODB.Recordset
On Error GoTo errorhandler
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
rs.ActiveConnection = CurrentProject.Connection
rs.Open ("select * from MySelectedObservations")
Dim objWord As Word.Application
Dim pathgetter As String
Dim doc As Word.Document
Dim WordHeaderFooter As HeaderFooter
Dim filepath As String
Set objWord = CreateObject("Word.Application")
pathgetter = DLookup("Word_Path_Field", "WORD_PATH_TBL", "Serial = 1")
filepath = "" & pathgetter & "\Observations " & Format(Now(), "dd-mm-yyyy") & ".docx"
With objWord
.Visible = True
Set doc = .Documents.Open(filepath)
End With
With objWord.Selection
.Font.Name = "Times New Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = True
.Font.Underline = wdUnderlineSingle
'.Font.Bold = True
.TypeText Observation_Heading.Value
.TypeText ":"
.TypeParagraph
.Font.Name = "Times New Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = False
.Font.Underline = wdUnderlineNone
.TypeText Observation_Details.Value
.TypeParagraph
.TypeParagraph
.Font.Name = "Times New Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = True
.Font.Underline = wdUnderlineNone
.TypeText "Risk Implication: "
.Font.Name = "Times New Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = False
.Font.Underline = wdUnderlineNone
.TypeText Risk_Implication.Value
.TypeParagraph
.Font.Name = "Times new Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = True
.Font.Underline = wdUnderlineNone
.TypeText "Risk Category: "
.TypeParagraph
.Font.Name = "Times New Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = False
.Font.Underline = wdUnderlineNone
.TypeText Risk_Category.Value
.TypeParagraph
.Font.Name = "Times New Roman"
.Font.Size = 10
.Font.TextColor = vbBlack
.Font.Bold = True
.Font.Underline = wdUnderlineNone
.TypeText "Branch Remarks: "
.TypeParagraph
.TypeParagraph
End With
doc.Save
doc.Activate
errorhandler:
MsgBox Err.Description
End Sub
Can anybody help me