m_court15
08-27-2012, 05:38 AM
I have a userform where a user selects a word file and then it populates the userform. I recently had to add an object variable: oVars("wear").Value.
My problem is the old saved word files do not have this object, so when the old word files are opened in my userform, it errors out. Is there anyway to check for this variable and then ignore it if it is not present?
here is my code for opoening the word file in my userform:
Option Explicit
Private oVars As Variables
Private Sub cmdAddSave_Click()
'POPULATES DOCUMENT WITH VARIABLES
Set oVars = ActiveDocument.Variables
'oVars("DieType").Value = "pultrusion hv die"
oVars("DieNo").Value = Me.txtDieNo
oVars("RunDate").Value = Me.txtRunDate
oVars("DieInternalSuraface").Value = Me.txtDieInternalSuraface
oVars("InternalDamage").Value = Me.txtInternalDamage
oVars("InternalChrome").Value = Me.txtInternalChrome
oVars("InternalSurface").Value = Me.txtInternalSurface
oVars("AFace").Value = Me.txtAFace
oVars("ADamage").Value = Me.txtADamage
oVars("BFace").Value = Me.txtBFace
oVars("BDamage").Value = Me.txtBDamage
oVars("BatchNo").Value = Me.txtBatchNo
oVars("ACT1").Value = Me.LabelACT1
oVars("AChrome").Value = Me.txtAChrome
oVars("ACT2").Value = Me.LabelACT2
oVars("txtACT2").Value = Me.txtACT2
oVars("ACT3").Value = Me.LabelACT3
oVars("txtACT3").Value = Me.txtACT3
oVars("SF4").Value = Me.txtSF4
oVars("ASF1").Value = Me.LabelASF1
oVars("ASurface").Value = Me.txtASurface
oVars("ASF2").Value = Me.LabelASF2
oVars("AP6").Value = Me.txtAp6
oVars("BCT1").Value = Me.LabelBCT1
oVars("BChrome").Value = Me.txtBChrome
oVars("BCT2").Value = Me.LabelBCT2
oVars("txtBCT2").Value = Me.txtBCT2
oVars("BCT3").Value = Me.LabelBCT3
oVars("txtBCT3").Value = Me.txtBCT3
oVars("BSF1").Value = Me.LabelBSF1
oVars("BSurface").Value = Me.txtBSurface
oVars("BSF2").Value = Me.LabelBSF2
oVars("AP9").Value = Me.txtAP9
oVars("SF5").Value = Me.txtSF5
oVars("SF6").Value = Me.txtSF6
oVars("CT4").Value = Me.txtCT4
oVars("CT5").Value = Me.txtCT5
oVars("CT6").Value = Me.txtCT6
oVars("AP1").Value = Me.txtAP1
oVars("AP2").Value = Me.txtAP2
oVars("AP3").Value = Me.txtAP3
oVars("AP4").Value = Me.txtAP4
oVars("AP7").Value = Me.txtAP7
oVars("AP10").Value = Me.txtAP10
oVars("AP11").Value = Me.txtAP11
oVars("AP12").Value = Me.txtAP12
oVars("AP13").Value = Me.txtAP13
oVars("AP14").Value = Me.txtAP14
oVars("AP15").Value = Me.txtAP15
oVars("DieCondition").Value = Me.txtDieCondition
oVars("Description").Value = Me.txtDescription
oVars("Size").Value = Me.txtSize
oVars("DieShape").Value = Me.txtDieShape
oVars("FTran").Value = Me.txtFTran
oVars("name").Value = Me.txtName
oVars("weawr").Value = Me.txtWear
'LEAVES FIELD BLANK IF NOTHING IS ENTERED
If Me.txtAP15 = "" Then
oVars("AP15").Value = " "
Else
oVars("AP15").Value = Me.txtAP15
End If
If Me.txtAP14 = "" Then
oVars("AP14").Value = " "
Else
oVars("AP14").Value = Me.txtAP14
End If
If Me.txtAP13 = "" Then
oVars("AP13").Value = " "
Else
oVars("AP13").Value = Me.txtAP13
End If
If Me.txtAP12 = "" Then
oVars("AP12").Value = " "
Else
oVars("AP12").Value = Me.txtAP12
End If
If Me.txtAP11 = "" Then
oVars("AP11").Value = " "
Else
oVars("AP11").Value = Me.txtAP11
End If
If Me.txtAP10 = "" Then
oVars("AP10").Value = " "
Else
oVars("AP10").Value = Me.txtAP10
End If
If Me.txtAP9 = "" Then
oVars("AP9").Value = " "
Else
oVars("AP9").Value = Me.txtAP9
End If
If Me.txtAP7 = "" Then
oVars("AP7").Value = " "
Else
oVars("AP7").Value = Me.txtAP7
End If
If Me.txtAp6 = "" Then
oVars("AP6").Value = " "
Else
oVars("AP6").Value = Me.txtAp6
End If
If Me.txtAP4 = "" Then
oVars("AP4").Value = " "
Else
oVars("AP4").Value = Me.txtAP4
End If
If Me.txtAP3 = "" Then
oVars("AP3").Value = " "
Else
oVars("AP3").Value = Me.txtAP3
End If
If Me.txtAP2 = "" Then
oVars("AP2").Value = " "
Else
oVars("AP2").Value = Me.txtAP2
End If
If Me.txtAP1 = "" Then
oVars("AP1").Value = " "
Else
oVars("AP1").Value = Me.txtAP1
End If
If Me.txtDieNo = "" Then
oVars("DieNo").Value = " "
Else
oVars("Dieno").Value = Me.txtDieNo
End If
If Me.txtRunDate = "" Then
oVars("RunDate").Value = " "
Else
oVars("RunDate").Value = Me.txtRunDate
End If
If Me.txtDieInternalSuraface = "" Then
oVars("DieInternalSuraface").Value = " "
Else
oVars("DieInternalSuraface").Value = Me.txtDieInternalSuraface
End If
If Me.txtInternalDamage = "" Then
oVars("InternalDamage").Value = " "
Else
oVars("InternalDamage").Value = Me.txtInternalDamage
End If
If Me.txtInternalChrome = "" Then
oVars("InternalChrome").Value = " "
Else
oVars("InternalChrome").Value = Me.txtInternalChrome
End If
If Me.txtInternalSurface = "" Then
oVars("InternalSurface").Value = " "
Else
oVars("InternalSurface").Value = Me.txtInternalSurface
End If
If Me.txtAFace = "" Then
oVars("AFace").Value = " "
Else
oVars("AFace").Value = Me.txtAFace
End If
If Me.txtADamage = "" Then
oVars("ADamage").Value = " "
Else
oVars("ADamage").Value = Me.txtADamage
End If
If Me.txtAChrome = "" Then
oVars("AChrome").Value = " "
Else
oVars("AChrome").Value = Me.txtAChrome
End If
If Me.txtASurface = "" Then
oVars("ASurface").Value = " "
Else
oVars("ASurface").Value = Me.txtASurface
End If
If Me.txtBFace = "" Then
oVars("BFace").Value = " "
Else
oVars("BFace").Value = Me.txtBFace
End If
If Me.txtBDamage = "" Then
oVars("BDamage").Value = " "
Else
oVars("BDamage").Value = Me.txtBDamage
End If
If Me.txtBChrome = "" Then
oVars("BChrome").Value = " "
Else
oVars("BChrome").Value = Me.txtBChrome
End If
If Me.txtBSurface = "" Then
oVars("BSurface").Value = " "
Else
oVars("BSurface").Value = Me.txtBSurface
End If
If Me.txtBatchNo = "" Then
oVars("BatchNo").Value = " "
Else
oVars("BatchNo").Value = Me.txtBatchNo
End If
If Me.txtCT6 = "" Then
oVars("CT6").Value = " "
Else
oVars("CT6").Value = Me.txtCT6
End If
If Me.txtCT5 = "" Then
oVars("CT5").Value = " "
Else
oVars("CT5").Value = Me.txtCT5
End If
If Me.txtCT4 = "" Then
oVars("CT4").Value = " "
Else
oVars("CT4").Value = Me.txtCT4
End If
If Me.txtSF6 = "" Then
oVars("SF6").Value = " "
Else
oVars("SF6").Value = Me.txtSF6
End If
If Me.txtSF5 = "" Then
oVars("SF5").Value = " "
Else
oVars("SF5").Value = Me.txtSF5
End If
If Me.txtSF4 = "" Then
oVars("SF4").Value = " "
Else
oVars("SF4").Value = Me.txtSF4
End If
If Me.txtDieCondition = "" Then
oVars("DieCondition").Value = " "
Else
oVars("DieCondition").Value = Me.txtDieCondition
End If
If Me.txtDescription = "" Then
oVars("description").Value = " "
Else
oVars("Description").Value = Me.txtDescription
End If
If Me.txtSize = "" Then
oVars("Size").Value = " "
Else
oVars("Size").Value = Me.txtSize
End If
If Me.txtFTran = "" Then
oVars("FTran").Value = " "
Else
oVars("FTran").Value = Me.txtFTran
End If
If Me.txtName = "" Then
oVars("name").Value = " "
Else
oVars("name").Value = Me.txtName
End If
If Me.txtWear = "" Then
oVars("wear").Value = " "
Else
oVars("wear").Value = Me.txtWear
End If
ActiveDocument.Fields.Update
Set oVars = Nothing
Unload Me
'SAVE FUNCTION
On Error Resume Next
Dim strFileName As String
Dim strdir As String
Dim strNewFile As String
'save pdf with name that is diplayed in textbox1
strdir = "\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\view only\die\"
strFileName = Me.TextBox1 & ".pdf"
strNewFile = strdir & strFileName
ActiveDocument.SaveAs strNewFile, FileFormat:=wdFormatPDF
ActiveDocument.Close savechanges:=True
MainMenu.Show
End Sub
Private Sub cmdBack_Click()
'GOES BACK TO MAIN MENU
Unload Me
ActiveDocument.Close savechanges:=False
MainMenu.Show
End Sub
Private Sub cmdClose_Click()
'CLOSES FORM WITH OUT SAVING
Unload Me
ActiveDocument.Close savechanges:=False
End Sub
Private Sub UserForm_Initialize()
'OPENS OPEN DIALOG BOX
Dim fd As FileDialog
Dim ffs As FileDialogFilters
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
Set ffs = .Filters
With ffs
.Clear
.Add "wdFormatXMLDocument", "*.docx"
End With
.InitialFileName = "\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\edit\die\HV\"
If .Show = 0 Then ActiveDocument.Close savechanges:=False 'user pressed the cancel button
'Else
.Execute
'End If
End With
Set fd = Nothing
'populates userform from word document
Set oVars = ActiveDocument.Variables
Me.labelDie = oVars("DieType").Value
Me.txtDieNo = oVars("DieNo").Value
Me.txtRunDate = oVars("RunDate").Value
Me.txtDieInternalSuraface = oVars("DieInternalSuraface").Value
Me.txtInternalDamage = oVars("InternalDamage").Value
Me.txtInternalChrome = oVars("InternalChrome").Value
Me.txtInternalSurface = oVars("InternalSurface").Value
Me.txtAFace = oVars("AFace").Value
Me.txtADamage = oVars("ADamage").Value
Me.txtAChrome = oVars("AChrome").Value
Me.txtASurface = oVars("ASurface").Value
Me.txtBFace = oVars("BFace").Value
Me.txtBDamage = oVars("BDamage").Value
Me.txtBChrome = oVars("BChrome").Value
Me.txtBSurface = oVars("BSurface").Value
Me.txtBatchNo = oVars("BatchNo").Value
Me.LabelACT1 = oVars("ACT1").Value
Me.LabelACT2 = oVars("ACT2").Value
Me.txtACT2 = oVars("txtACT2").Value
Me.LabelACT3 = oVars("ACT3").Value
Me.txtACT3 = oVars("txtACT3").Value
Me.LabelASF1 = oVars("ASF1").Value
Me.LabelASF2 = oVars("ASF2").Value
Me.LabelBCT1 = oVars("BCT1").Value
Me.LabelBCT2 = oVars("BCT2").Value
Me.txtBCT2 = oVars("txtBCT2").Value
Me.LabelBCT3 = oVars("BCT3").Value
Me.txtBCT3 = oVars("txtBCT3").Value
Me.LabelBSF1 = oVars("BSF1").Value
Me.LabelBSF2 = oVars("BSF2").Value
Me.txtSF4 = oVars("SF4").Value
Me.txtSF5 = oVars("SF5").Value
Me.txtSF6 = oVars("SF6").Value
Me.txtCT4 = oVars("CT4").Value
Me.txtCT5 = oVars("CT5").Value
Me.txtCT6 = oVars("CT6").Value
Me.txtAP1 = oVars("AP1").Value
Me.txtAP2 = oVars("AP2").Value
Me.txtAP3 = oVars("AP3").Value
Me.txtAP4 = oVars("AP4").Value
Me.txtAp6 = oVars("AP6").Value
Me.txtAP7 = oVars("AP7").Value
Me.txtAP9 = oVars("AP9").Value
Me.txtAP10 = oVars("AP10").Value
Me.txtAP11 = oVars("AP11").Value
Me.txtAP12 = oVars("AP12").Value
Me.txtAP13 = oVars("AP13").Value
Me.txtAP14 = oVars("AP14").Value
Me.txtAP15 = oVars("AP15").Value
Me.labelDie = oVars("DieType").Value
Me.txtDieCondition = oVars("DieCondition").Value
Me.txtDescription = oVars("Description").Value
Me.txtSize = oVars("Size").Value
Me.txtDateNew = oVars("DateNew").Value
Me.txtDieShape = oVars("DieShape").Value
Me.txtFTran = oVars("FTran").Value
Me.txtName = oVars("name").Value
Me.txtWear = oVars("wear").Value
'If txtCTF1 = "N/A" Then txtCTF1.Enabled = False
'display file name in textbox1 without extension
'Me.TextBox1 = Mid(ActiveDocument.name, 1, Len(ActiveDocument.name) - 5)
'Me.TextBox1 = Split(ActiveDocument.name, ".")(0)
Me.TextBox1 = Left(ActiveDocument.name, InStrRev(ActiveDocument.name, ".") - 1)
'ADDS PICTURE TO USERFORM DEPENDING ON DIE TYPE
If Me.labelDie = "U Shape Die Inspection form" Then
Image1.Picture = LoadPicture("\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\images\U Shape.jpg")
End If
If Me.labelDie = "Square Die Inspection form" Then
Image1.Picture = LoadPicture("\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\images\SquareDie.jpg")
End If
If Me.labelDie = "Round Die Inspection form" Then
Image1.Picture = LoadPicture("\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\images\Round.jpg")
End If
If Me.labelDie = "C Channel Die Inspection form" Then
Image1.Picture = LoadPicture("\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\images\Cchannel.jpg")
End If
If Me.labelDie = "HV Die Inspection form" Then
Image1.Picture = LoadPicture("\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\images\HV.jpg")
End If
ActiveDocument.Fields.Update
Application.ScreenUpdating = True
Application.Visible = False
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
' Prevents use of the Close button
If CloseMode = vbFormControlMenu Then
MsgBox "Clicking the Close button does not work."
Cancel = True
End If
End Sub
My problem is the old saved word files do not have this object, so when the old word files are opened in my userform, it errors out. Is there anyway to check for this variable and then ignore it if it is not present?
here is my code for opoening the word file in my userform:
Option Explicit
Private oVars As Variables
Private Sub cmdAddSave_Click()
'POPULATES DOCUMENT WITH VARIABLES
Set oVars = ActiveDocument.Variables
'oVars("DieType").Value = "pultrusion hv die"
oVars("DieNo").Value = Me.txtDieNo
oVars("RunDate").Value = Me.txtRunDate
oVars("DieInternalSuraface").Value = Me.txtDieInternalSuraface
oVars("InternalDamage").Value = Me.txtInternalDamage
oVars("InternalChrome").Value = Me.txtInternalChrome
oVars("InternalSurface").Value = Me.txtInternalSurface
oVars("AFace").Value = Me.txtAFace
oVars("ADamage").Value = Me.txtADamage
oVars("BFace").Value = Me.txtBFace
oVars("BDamage").Value = Me.txtBDamage
oVars("BatchNo").Value = Me.txtBatchNo
oVars("ACT1").Value = Me.LabelACT1
oVars("AChrome").Value = Me.txtAChrome
oVars("ACT2").Value = Me.LabelACT2
oVars("txtACT2").Value = Me.txtACT2
oVars("ACT3").Value = Me.LabelACT3
oVars("txtACT3").Value = Me.txtACT3
oVars("SF4").Value = Me.txtSF4
oVars("ASF1").Value = Me.LabelASF1
oVars("ASurface").Value = Me.txtASurface
oVars("ASF2").Value = Me.LabelASF2
oVars("AP6").Value = Me.txtAp6
oVars("BCT1").Value = Me.LabelBCT1
oVars("BChrome").Value = Me.txtBChrome
oVars("BCT2").Value = Me.LabelBCT2
oVars("txtBCT2").Value = Me.txtBCT2
oVars("BCT3").Value = Me.LabelBCT3
oVars("txtBCT3").Value = Me.txtBCT3
oVars("BSF1").Value = Me.LabelBSF1
oVars("BSurface").Value = Me.txtBSurface
oVars("BSF2").Value = Me.LabelBSF2
oVars("AP9").Value = Me.txtAP9
oVars("SF5").Value = Me.txtSF5
oVars("SF6").Value = Me.txtSF6
oVars("CT4").Value = Me.txtCT4
oVars("CT5").Value = Me.txtCT5
oVars("CT6").Value = Me.txtCT6
oVars("AP1").Value = Me.txtAP1
oVars("AP2").Value = Me.txtAP2
oVars("AP3").Value = Me.txtAP3
oVars("AP4").Value = Me.txtAP4
oVars("AP7").Value = Me.txtAP7
oVars("AP10").Value = Me.txtAP10
oVars("AP11").Value = Me.txtAP11
oVars("AP12").Value = Me.txtAP12
oVars("AP13").Value = Me.txtAP13
oVars("AP14").Value = Me.txtAP14
oVars("AP15").Value = Me.txtAP15
oVars("DieCondition").Value = Me.txtDieCondition
oVars("Description").Value = Me.txtDescription
oVars("Size").Value = Me.txtSize
oVars("DieShape").Value = Me.txtDieShape
oVars("FTran").Value = Me.txtFTran
oVars("name").Value = Me.txtName
oVars("weawr").Value = Me.txtWear
'LEAVES FIELD BLANK IF NOTHING IS ENTERED
If Me.txtAP15 = "" Then
oVars("AP15").Value = " "
Else
oVars("AP15").Value = Me.txtAP15
End If
If Me.txtAP14 = "" Then
oVars("AP14").Value = " "
Else
oVars("AP14").Value = Me.txtAP14
End If
If Me.txtAP13 = "" Then
oVars("AP13").Value = " "
Else
oVars("AP13").Value = Me.txtAP13
End If
If Me.txtAP12 = "" Then
oVars("AP12").Value = " "
Else
oVars("AP12").Value = Me.txtAP12
End If
If Me.txtAP11 = "" Then
oVars("AP11").Value = " "
Else
oVars("AP11").Value = Me.txtAP11
End If
If Me.txtAP10 = "" Then
oVars("AP10").Value = " "
Else
oVars("AP10").Value = Me.txtAP10
End If
If Me.txtAP9 = "" Then
oVars("AP9").Value = " "
Else
oVars("AP9").Value = Me.txtAP9
End If
If Me.txtAP7 = "" Then
oVars("AP7").Value = " "
Else
oVars("AP7").Value = Me.txtAP7
End If
If Me.txtAp6 = "" Then
oVars("AP6").Value = " "
Else
oVars("AP6").Value = Me.txtAp6
End If
If Me.txtAP4 = "" Then
oVars("AP4").Value = " "
Else
oVars("AP4").Value = Me.txtAP4
End If
If Me.txtAP3 = "" Then
oVars("AP3").Value = " "
Else
oVars("AP3").Value = Me.txtAP3
End If
If Me.txtAP2 = "" Then
oVars("AP2").Value = " "
Else
oVars("AP2").Value = Me.txtAP2
End If
If Me.txtAP1 = "" Then
oVars("AP1").Value = " "
Else
oVars("AP1").Value = Me.txtAP1
End If
If Me.txtDieNo = "" Then
oVars("DieNo").Value = " "
Else
oVars("Dieno").Value = Me.txtDieNo
End If
If Me.txtRunDate = "" Then
oVars("RunDate").Value = " "
Else
oVars("RunDate").Value = Me.txtRunDate
End If
If Me.txtDieInternalSuraface = "" Then
oVars("DieInternalSuraface").Value = " "
Else
oVars("DieInternalSuraface").Value = Me.txtDieInternalSuraface
End If
If Me.txtInternalDamage = "" Then
oVars("InternalDamage").Value = " "
Else
oVars("InternalDamage").Value = Me.txtInternalDamage
End If
If Me.txtInternalChrome = "" Then
oVars("InternalChrome").Value = " "
Else
oVars("InternalChrome").Value = Me.txtInternalChrome
End If
If Me.txtInternalSurface = "" Then
oVars("InternalSurface").Value = " "
Else
oVars("InternalSurface").Value = Me.txtInternalSurface
End If
If Me.txtAFace = "" Then
oVars("AFace").Value = " "
Else
oVars("AFace").Value = Me.txtAFace
End If
If Me.txtADamage = "" Then
oVars("ADamage").Value = " "
Else
oVars("ADamage").Value = Me.txtADamage
End If
If Me.txtAChrome = "" Then
oVars("AChrome").Value = " "
Else
oVars("AChrome").Value = Me.txtAChrome
End If
If Me.txtASurface = "" Then
oVars("ASurface").Value = " "
Else
oVars("ASurface").Value = Me.txtASurface
End If
If Me.txtBFace = "" Then
oVars("BFace").Value = " "
Else
oVars("BFace").Value = Me.txtBFace
End If
If Me.txtBDamage = "" Then
oVars("BDamage").Value = " "
Else
oVars("BDamage").Value = Me.txtBDamage
End If
If Me.txtBChrome = "" Then
oVars("BChrome").Value = " "
Else
oVars("BChrome").Value = Me.txtBChrome
End If
If Me.txtBSurface = "" Then
oVars("BSurface").Value = " "
Else
oVars("BSurface").Value = Me.txtBSurface
End If
If Me.txtBatchNo = "" Then
oVars("BatchNo").Value = " "
Else
oVars("BatchNo").Value = Me.txtBatchNo
End If
If Me.txtCT6 = "" Then
oVars("CT6").Value = " "
Else
oVars("CT6").Value = Me.txtCT6
End If
If Me.txtCT5 = "" Then
oVars("CT5").Value = " "
Else
oVars("CT5").Value = Me.txtCT5
End If
If Me.txtCT4 = "" Then
oVars("CT4").Value = " "
Else
oVars("CT4").Value = Me.txtCT4
End If
If Me.txtSF6 = "" Then
oVars("SF6").Value = " "
Else
oVars("SF6").Value = Me.txtSF6
End If
If Me.txtSF5 = "" Then
oVars("SF5").Value = " "
Else
oVars("SF5").Value = Me.txtSF5
End If
If Me.txtSF4 = "" Then
oVars("SF4").Value = " "
Else
oVars("SF4").Value = Me.txtSF4
End If
If Me.txtDieCondition = "" Then
oVars("DieCondition").Value = " "
Else
oVars("DieCondition").Value = Me.txtDieCondition
End If
If Me.txtDescription = "" Then
oVars("description").Value = " "
Else
oVars("Description").Value = Me.txtDescription
End If
If Me.txtSize = "" Then
oVars("Size").Value = " "
Else
oVars("Size").Value = Me.txtSize
End If
If Me.txtFTran = "" Then
oVars("FTran").Value = " "
Else
oVars("FTran").Value = Me.txtFTran
End If
If Me.txtName = "" Then
oVars("name").Value = " "
Else
oVars("name").Value = Me.txtName
End If
If Me.txtWear = "" Then
oVars("wear").Value = " "
Else
oVars("wear").Value = Me.txtWear
End If
ActiveDocument.Fields.Update
Set oVars = Nothing
Unload Me
'SAVE FUNCTION
On Error Resume Next
Dim strFileName As String
Dim strdir As String
Dim strNewFile As String
'save pdf with name that is diplayed in textbox1
strdir = "\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\view only\die\"
strFileName = Me.TextBox1 & ".pdf"
strNewFile = strdir & strFileName
ActiveDocument.SaveAs strNewFile, FileFormat:=wdFormatPDF
ActiveDocument.Close savechanges:=True
MainMenu.Show
End Sub
Private Sub cmdBack_Click()
'GOES BACK TO MAIN MENU
Unload Me
ActiveDocument.Close savechanges:=False
MainMenu.Show
End Sub
Private Sub cmdClose_Click()
'CLOSES FORM WITH OUT SAVING
Unload Me
ActiveDocument.Close savechanges:=False
End Sub
Private Sub UserForm_Initialize()
'OPENS OPEN DIALOG BOX
Dim fd As FileDialog
Dim ffs As FileDialogFilters
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
Set ffs = .Filters
With ffs
.Clear
.Add "wdFormatXMLDocument", "*.docx"
End With
.InitialFileName = "\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\edit\die\HV\"
If .Show = 0 Then ActiveDocument.Close savechanges:=False 'user pressed the cancel button
'Else
.Execute
'End If
End With
Set fd = Nothing
'populates userform from word document
Set oVars = ActiveDocument.Variables
Me.labelDie = oVars("DieType").Value
Me.txtDieNo = oVars("DieNo").Value
Me.txtRunDate = oVars("RunDate").Value
Me.txtDieInternalSuraface = oVars("DieInternalSuraface").Value
Me.txtInternalDamage = oVars("InternalDamage").Value
Me.txtInternalChrome = oVars("InternalChrome").Value
Me.txtInternalSurface = oVars("InternalSurface").Value
Me.txtAFace = oVars("AFace").Value
Me.txtADamage = oVars("ADamage").Value
Me.txtAChrome = oVars("AChrome").Value
Me.txtASurface = oVars("ASurface").Value
Me.txtBFace = oVars("BFace").Value
Me.txtBDamage = oVars("BDamage").Value
Me.txtBChrome = oVars("BChrome").Value
Me.txtBSurface = oVars("BSurface").Value
Me.txtBatchNo = oVars("BatchNo").Value
Me.LabelACT1 = oVars("ACT1").Value
Me.LabelACT2 = oVars("ACT2").Value
Me.txtACT2 = oVars("txtACT2").Value
Me.LabelACT3 = oVars("ACT3").Value
Me.txtACT3 = oVars("txtACT3").Value
Me.LabelASF1 = oVars("ASF1").Value
Me.LabelASF2 = oVars("ASF2").Value
Me.LabelBCT1 = oVars("BCT1").Value
Me.LabelBCT2 = oVars("BCT2").Value
Me.txtBCT2 = oVars("txtBCT2").Value
Me.LabelBCT3 = oVars("BCT3").Value
Me.txtBCT3 = oVars("txtBCT3").Value
Me.LabelBSF1 = oVars("BSF1").Value
Me.LabelBSF2 = oVars("BSF2").Value
Me.txtSF4 = oVars("SF4").Value
Me.txtSF5 = oVars("SF5").Value
Me.txtSF6 = oVars("SF6").Value
Me.txtCT4 = oVars("CT4").Value
Me.txtCT5 = oVars("CT5").Value
Me.txtCT6 = oVars("CT6").Value
Me.txtAP1 = oVars("AP1").Value
Me.txtAP2 = oVars("AP2").Value
Me.txtAP3 = oVars("AP3").Value
Me.txtAP4 = oVars("AP4").Value
Me.txtAp6 = oVars("AP6").Value
Me.txtAP7 = oVars("AP7").Value
Me.txtAP9 = oVars("AP9").Value
Me.txtAP10 = oVars("AP10").Value
Me.txtAP11 = oVars("AP11").Value
Me.txtAP12 = oVars("AP12").Value
Me.txtAP13 = oVars("AP13").Value
Me.txtAP14 = oVars("AP14").Value
Me.txtAP15 = oVars("AP15").Value
Me.labelDie = oVars("DieType").Value
Me.txtDieCondition = oVars("DieCondition").Value
Me.txtDescription = oVars("Description").Value
Me.txtSize = oVars("Size").Value
Me.txtDateNew = oVars("DateNew").Value
Me.txtDieShape = oVars("DieShape").Value
Me.txtFTran = oVars("FTran").Value
Me.txtName = oVars("name").Value
Me.txtWear = oVars("wear").Value
'If txtCTF1 = "N/A" Then txtCTF1.Enabled = False
'display file name in textbox1 without extension
'Me.TextBox1 = Mid(ActiveDocument.name, 1, Len(ActiveDocument.name) - 5)
'Me.TextBox1 = Split(ActiveDocument.name, ".")(0)
Me.TextBox1 = Left(ActiveDocument.name, InStrRev(ActiveDocument.name, ".") - 1)
'ADDS PICTURE TO USERFORM DEPENDING ON DIE TYPE
If Me.labelDie = "U Shape Die Inspection form" Then
Image1.Picture = LoadPicture("\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\images\U Shape.jpg")
End If
If Me.labelDie = "Square Die Inspection form" Then
Image1.Picture = LoadPicture("\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\images\SquareDie.jpg")
End If
If Me.labelDie = "Round Die Inspection form" Then
Image1.Picture = LoadPicture("\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\images\Round.jpg")
End If
If Me.labelDie = "C Channel Die Inspection form" Then
Image1.Picture = LoadPicture("\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\images\Cchannel.jpg")
End If
If Me.labelDie = "HV Die Inspection form" Then
Image1.Picture = LoadPicture("\\hfgpmain\engineering\pultrusion\tooling\inspection (file://\\hfgpmain\engineering\pultrusion\tooling\inspection) documents\images\HV.jpg")
End If
ActiveDocument.Fields.Update
Application.ScreenUpdating = True
Application.Visible = False
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
' Prevents use of the Close button
If CloseMode = vbFormControlMenu Then
MsgBox "Clicking the Close button does not work."
Cancel = True
End If
End Sub