J
jhawk
I'm trying to use Access 2003 VBA to automatically fill in a Word form with
text fields; however, in several instances, I'm having difficulty passing a
parsed string to a field. The following code is an example of what I've been
using.
Code:
strVerification = ""
If Forms!frmHazardsAndControls3_1.fraYesNo.Value = 1 Then
'Control 3.a) is applicable
If Forms!frmHazardsAndControls3_2.chk1.Value = -1 Then
docWord.FormFields("chk3a").CheckBox.Value = True
strVerification = strVerification & _
"3.a)1. Venting analysis.#" & _
"3.a)2. Review of Design.#" & _
"3.a)3. QA Inspection and certification of the as-built " & _
"hardware per approved design drawing.##"
End If
'Control 3.b) is applicable
If Forms!frmHazardsAndControls3_2.chk2.Value = -1 Then
docWord.FormFields("chk3b").CheckBox.Value = True
If Forms!frmHazardsAndControls3_2.txt3bEquivalentICD.Value <> "" Then
docWord.FormFields("bmkControl3b").Result = _
"(" &
Forms!frmHazardsAndControls3_2.txt3bEquivalentICD.Value & ")"
End If
strVerification = strVerification & _
"3.b)1. Venting analysis.#" & _
"3.b)2. Review of Design.#" & _
"3.b)3. QA Inspection and certification of the as-built " & _
"hardware per approved design drawing.##"
End If
'Control 3.c) is applicable
If Forms!frmHazardsAndControls3_2.chk3.Value = -1 Then
docWord.FormFields("chk3c").CheckBox.Value = True
If Forms!frmHazardsAndControls3_2.txt3cEquivalentICD.Value <> "" Then
docWord.FormFields("bmkControl3c").Result = _
"(" &
Forms!frmHazardsAndControls3_2.txt3cEquivalentICD.Value & ")"
End If
strVerification = strVerification & _
"3.c)1. Venting analysis.#" & _
"3.c)2. Review of Design.#" & _
"3.c)3. QA Inspection and certification of the as-built " & _
"hardware per approved design drawing.##"
End If
'Control 3.d) is applicable
If Forms!frmHazardsAndControls3_2.chk4.Value = -1 Then
docWord.FormFields("chk3d").CheckBox.Value = True
strVerification = strVerification & _
"3.d)1. Venting analysis.#" & _
"3.d)2. Review of Design.#" & _
"3.d)3. QA Inspection and certification of the as-built " & _
"hardware per approved design drawing.##"
End If
If Forms!frmHazardsAndControls3_2.chk1.Value = 0 _
And Forms!frmHazardsAndControls3_2.chk2.Value = 0 _
And Forms!frmHazardsAndControls3_2.chk3.Value = 0 _
And Forms!frmHazardsAndControls3_2.chk4.Value = 0 Then
strVerification = "See Unique Hazard Report: (fill in HR number here)"
End If
docWord.FormFields("bmkVerification3").Result = strVerification
Else
'Hazard is not applicable
docWord.FormFields("bmkVerification3").Result = _
"N/A, no intentionally vented containers."
End If
When I run the code, if more than one checkbox is selected, the string
strVerification parses together quite nicely within Access (I've checked this
with breakpoints and the Locals window in VBE), but...when it comes time to
pass it to the Word document, nothing happens. The text field remains blank.
If only one check box is selected, there's no problem at all, and the string
passes fine to the Word document.
Similarly, but a little more strangely, I've got other instances of code
that are similar in structure, but up to 3 check boxes can be selected and
the string will parse and pass to Word without any problem, but with 4 or 5
checkboxes selected, the string won't pass.
I've compared the different instances of code without finding any
differences in the structure, and am really at a loss why this is happening.
Any idea what might be causing this, and how I can fix it? I'm not a
professional developer, so even the most basic advice is appreciated.
Cheers.
text fields; however, in several instances, I'm having difficulty passing a
parsed string to a field. The following code is an example of what I've been
using.
Code:
strVerification = ""
If Forms!frmHazardsAndControls3_1.fraYesNo.Value = 1 Then
'Control 3.a) is applicable
If Forms!frmHazardsAndControls3_2.chk1.Value = -1 Then
docWord.FormFields("chk3a").CheckBox.Value = True
strVerification = strVerification & _
"3.a)1. Venting analysis.#" & _
"3.a)2. Review of Design.#" & _
"3.a)3. QA Inspection and certification of the as-built " & _
"hardware per approved design drawing.##"
End If
'Control 3.b) is applicable
If Forms!frmHazardsAndControls3_2.chk2.Value = -1 Then
docWord.FormFields("chk3b").CheckBox.Value = True
If Forms!frmHazardsAndControls3_2.txt3bEquivalentICD.Value <> "" Then
docWord.FormFields("bmkControl3b").Result = _
"(" &
Forms!frmHazardsAndControls3_2.txt3bEquivalentICD.Value & ")"
End If
strVerification = strVerification & _
"3.b)1. Venting analysis.#" & _
"3.b)2. Review of Design.#" & _
"3.b)3. QA Inspection and certification of the as-built " & _
"hardware per approved design drawing.##"
End If
'Control 3.c) is applicable
If Forms!frmHazardsAndControls3_2.chk3.Value = -1 Then
docWord.FormFields("chk3c").CheckBox.Value = True
If Forms!frmHazardsAndControls3_2.txt3cEquivalentICD.Value <> "" Then
docWord.FormFields("bmkControl3c").Result = _
"(" &
Forms!frmHazardsAndControls3_2.txt3cEquivalentICD.Value & ")"
End If
strVerification = strVerification & _
"3.c)1. Venting analysis.#" & _
"3.c)2. Review of Design.#" & _
"3.c)3. QA Inspection and certification of the as-built " & _
"hardware per approved design drawing.##"
End If
'Control 3.d) is applicable
If Forms!frmHazardsAndControls3_2.chk4.Value = -1 Then
docWord.FormFields("chk3d").CheckBox.Value = True
strVerification = strVerification & _
"3.d)1. Venting analysis.#" & _
"3.d)2. Review of Design.#" & _
"3.d)3. QA Inspection and certification of the as-built " & _
"hardware per approved design drawing.##"
End If
If Forms!frmHazardsAndControls3_2.chk1.Value = 0 _
And Forms!frmHazardsAndControls3_2.chk2.Value = 0 _
And Forms!frmHazardsAndControls3_2.chk3.Value = 0 _
And Forms!frmHazardsAndControls3_2.chk4.Value = 0 Then
strVerification = "See Unique Hazard Report: (fill in HR number here)"
End If
docWord.FormFields("bmkVerification3").Result = strVerification
Else
'Hazard is not applicable
docWord.FormFields("bmkVerification3").Result = _
"N/A, no intentionally vented containers."
End If
When I run the code, if more than one checkbox is selected, the string
strVerification parses together quite nicely within Access (I've checked this
with breakpoints and the Locals window in VBE), but...when it comes time to
pass it to the Word document, nothing happens. The text field remains blank.
If only one check box is selected, there's no problem at all, and the string
passes fine to the Word document.
Similarly, but a little more strangely, I've got other instances of code
that are similar in structure, but up to 3 check boxes can be selected and
the string will parse and pass to Word without any problem, but with 4 or 5
checkboxes selected, the string won't pass.
I've compared the different instances of code without finding any
differences in the structure, and am really at a loss why this is happening.
Any idea what might be causing this, and how I can fix it? I'm not a
professional developer, so even the most basic advice is appreciated.
Cheers.