megha
12-07-2009, 10:58 AM
I am working on a macro for word document that save to specific drive on a click and stamp date and time. Its work fine.
I have included text boxes on document and reference them into code to MUST fill-in that information otherwise the message box appear to ask to fill-in the info. This part of my code is not working. When I click the command button to save the file with empty text boxes the message box does not appear to ask to fill-in the info.
I am using the following code. I would appreciate any help. Thanks!
Private Sub CommandButton1_Click()
Dim sFileName As String
Dim sPath As String
If txtDate.Value = " " Then
MsgBox "Please Enter Date", vbCritical
ElseIf txtShift.Value = " " Then
MsgBox "Please Enter Tank #", vbCritical
ElseIf txtShift1.Value = " " Then
MsgBox "Please Enter Calculated Tape", vbCritical
ElseIf txtShift2.Value = " " Then
MsgBox "Please Enter Local Varec", vbCritical
ElseIf txtShift3.Value = " " Then
MsgBox "Please Enter OMCC Gauge", vbCritical
ElseIf txtShift4.Value = " " Then
MsgBox "Please Enter Difference", vbCritical
Else
CommandButton1.Enabled = False
sFileName = Format(DateValue(Now()), "mmm_dd_yyyy") & "_" & _
Format(TimeSerial(Hour(Now()), Minute(Now()), Second(Now())), "hh_mm_ss_AM/PM") & "TANK" & txtShift.Value
sPath = "S:\OMCC\Tank Gauging/"
ThisDocument.SaveAs FileName:=sPath & sFileName, FileFormat:=xlNormal, ReadOnlyRecommended:=False
Application.Documents.Close
End If
End Sub
I have included text boxes on document and reference them into code to MUST fill-in that information otherwise the message box appear to ask to fill-in the info. This part of my code is not working. When I click the command button to save the file with empty text boxes the message box does not appear to ask to fill-in the info.
I am using the following code. I would appreciate any help. Thanks!
Private Sub CommandButton1_Click()
Dim sFileName As String
Dim sPath As String
If txtDate.Value = " " Then
MsgBox "Please Enter Date", vbCritical
ElseIf txtShift.Value = " " Then
MsgBox "Please Enter Tank #", vbCritical
ElseIf txtShift1.Value = " " Then
MsgBox "Please Enter Calculated Tape", vbCritical
ElseIf txtShift2.Value = " " Then
MsgBox "Please Enter Local Varec", vbCritical
ElseIf txtShift3.Value = " " Then
MsgBox "Please Enter OMCC Gauge", vbCritical
ElseIf txtShift4.Value = " " Then
MsgBox "Please Enter Difference", vbCritical
Else
CommandButton1.Enabled = False
sFileName = Format(DateValue(Now()), "mmm_dd_yyyy") & "_" & _
Format(TimeSerial(Hour(Now()), Minute(Now()), Second(Now())), "hh_mm_ss_AM/PM") & "TANK" & txtShift.Value
sPath = "S:\OMCC\Tank Gauging/"
ThisDocument.SaveAs FileName:=sPath & sFileName, FileFormat:=xlNormal, ReadOnlyRecommended:=False
Application.Documents.Close
End If
End Sub