D
DS
Can anyone let me know if this if Statement is correct. It works but
looks a little scary !
Thanks
DS
Private Sub ImageSave_Click()
Me.CommandHide.SetFocus
If IsNull(Me.TxtName) _
Or Me.TxtName = "" _
Or IsNull(Me.TxtType) _
Or Me.TxtType = "" _
Or IsNull(Me.TxtWorth) _
Or Me.TxtWorth = "" _
Or IsNull(Me.TxtPercent) _
Or IsNull(Me.TxtExp) _
Or Me.TxtExp = "" _
Then
DoCmd.OpenForm "FXMsgWarning"
Forms!FXMsgWarning!TxtMsg = "EMPTY FIELD"
ElseIf Me.TxtAction = 0 Then
If Me.TxtWorth = "Dollar" Then
Me.CommandHide.SetFocus
Me.TxtStatus = "SAVED"
Me.TxtID = Nz(DMax("[PaymentNameID]", "PayName"), 0) + 1
Dim DSQL As String
DoCmd.SetWarnings False
DSQL = "INSERT INTO PayName " & _
"(PaymentNameID,PaymentName,PaymentType,ExpirationDate,Active, " & _
"CouponType,CouponWorth,CouponAmount) " & _
"Values(" & Forms!CouponNames!TxtID & ", " & _
"'" & Forms!CouponNames!TxtName & "', " & _
"" & 3 & ", " & _
"" & Format(Forms!CouponNames![TxtExp],
"\#mm\/dd\/yyyy\#") & ", " & _
"" & Forms!CouponNames![ChkActive] & ", " & _
"" & Forms!CouponNames!TxtType & ", " & _
"'" & "Dollar" & "', " & _
"'" & Forms!CouponNames!TxtAmount & "')"
DoCmd.RunSQL (DSQL)
DoCmd.SetWarnings True
Me.ListCoupons.Requery
Me.TxtStatus = ""
Me.TxtID = 0
Me.TxtName = ""
Me.TxtType = ""
Me.ChkActive = -1
Me.LblActive.Visible = True
Me.TxtWorth = ""
Me.TxtExp = Date
Me.TxtAmount.Visible = False
Me.Label37.Visible = False
Me.TxtPercent.Visible = False
Me.Label38.Visible = False
ElseIf Me.TxtWorth = "Percent" Then
Me.CommandHide.SetFocus
Me.TxtStatus = "SAVED"
Me.TxtID = Nz(DMax("[PaymentNameID]", "PayName"), 0) + 1
Dim PSQL As String
DoCmd.SetWarnings False
PSQL = "INSERT INTO PayName " & _
"(PaymentNameID,PaymentName,PaymentType,ExpirationDate,Active, " & _
"CouponType,CouponWorth,CouponPercent) " & _
"Values(" & Forms!CouponNames!TxtID & ", " & _
"'" & Forms!CouponNames!TxtName & "', " & _
"" & 3 & ", " & _
"" & Format(Forms!CouponNames![TxtExp],
"\#mm\/dd\/yyyy\#") & ", " & _
"" & Forms!CouponNames![ChkActive] & ", " & _
"" & Forms!CouponNames!TxtType & ", " & _
"'" & "Percent" & "', " & _
"'" & Forms!CouponNames!TxtPercent & "')"
DoCmd.RunSQL (PSQL)
DoCmd.SetWarnings True
Me.ListCoupons.Requery
Me.TxtStatus = ""
Me.TxtID = ""
Me.TxtName = ""
Me.TxtType = ""
Me.ChkActive = -1
Me.LblActive.Visible = True
Me.TxtWorth = ""
Me.TxtAmount.Visible = False
Me.Label37.Visible = False
Me.TxtPercent.Visible = False
Me.Label38.Visible = False
End If
ElseIf Me.TxtAction = 1 Then
If Me.TxtWorth = "Dollar" Then
Me.CommandHide.SetFocus
Dim DollUpSQL As String
DoCmd.SetWarnings False
DollUpSQL = "UPDATE PayName SET PayName.PaymentName =
Forms!CouponNames!TxtName, " & _
"PayName.Active = Forms!CouponNames!ChkActive, " & _
"PayName.CouponType = Forms!CouponNames!TxtType, " & _
"PayName.CouponWorth = Forms!CouponNames!TxtWorth, " & _
"PayName.CouponAmount = Forms!CouponNames!TxtAmount, " & _
"PayName.ExpirationDate = Forms!CouponNames!TxtExp " & _
"WHERE PayName.PaymentNameID = Forms!CouponNames!TxtID;"
DoCmd.RunSQL (DollUpSQL)
DoCmd.SetWarnings True
Me.ListCoupons.Requery
DoCmd.OpenForm "FXMsgInfo"
Forms!FXMsgInfo!TxtMsg = "UPDATE SUCCESSFUL"
ElseIf Me.TxtWorth = "Percent" Then
Me.CommandHide.SetFocus
Dim PerUpSQL As String
DoCmd.SetWarnings False
PerUpSQL = "UPDATE PayName SET PayName.PaymentName =
Forms!CouponNames!TxtName, " & _
"PayName.Active = Forms!CouponNames!ChkActive, " & _
"PayName.CouponType = Forms!CouponNames!TxtType, " & _
"PayName.CouponWorth = Forms!CouponNames!TxtWorth, " & _
"PayName.CouponPercent = Forms!CouponNames!TxtPercent,
" & _
"PayName.ExpirationDate = Forms!CouponNames!TxtExp " & _
"WHERE PayName.PaymentNameID = Forms!CouponNames!TxtID;"
DoCmd.RunSQL (PerUpSQL)
DoCmd.SetWarnings True
Me.ListCoupons.Requery
DoCmd.OpenForm "FXMsgInfo"
Forms!FXMsgInfo!TxtMsg = "UPDATE SUCCESSFUL"
End If
End If
End Sub
looks a little scary !
Thanks
DS
Private Sub ImageSave_Click()
Me.CommandHide.SetFocus
If IsNull(Me.TxtName) _
Or Me.TxtName = "" _
Or IsNull(Me.TxtType) _
Or Me.TxtType = "" _
Or IsNull(Me.TxtWorth) _
Or Me.TxtWorth = "" _
Or IsNull(Me.TxtPercent) _
Or IsNull(Me.TxtExp) _
Or Me.TxtExp = "" _
Then
DoCmd.OpenForm "FXMsgWarning"
Forms!FXMsgWarning!TxtMsg = "EMPTY FIELD"
ElseIf Me.TxtAction = 0 Then
If Me.TxtWorth = "Dollar" Then
Me.CommandHide.SetFocus
Me.TxtStatus = "SAVED"
Me.TxtID = Nz(DMax("[PaymentNameID]", "PayName"), 0) + 1
Dim DSQL As String
DoCmd.SetWarnings False
DSQL = "INSERT INTO PayName " & _
"(PaymentNameID,PaymentName,PaymentType,ExpirationDate,Active, " & _
"CouponType,CouponWorth,CouponAmount) " & _
"Values(" & Forms!CouponNames!TxtID & ", " & _
"'" & Forms!CouponNames!TxtName & "', " & _
"" & 3 & ", " & _
"" & Format(Forms!CouponNames![TxtExp],
"\#mm\/dd\/yyyy\#") & ", " & _
"" & Forms!CouponNames![ChkActive] & ", " & _
"" & Forms!CouponNames!TxtType & ", " & _
"'" & "Dollar" & "', " & _
"'" & Forms!CouponNames!TxtAmount & "')"
DoCmd.RunSQL (DSQL)
DoCmd.SetWarnings True
Me.ListCoupons.Requery
Me.TxtStatus = ""
Me.TxtID = 0
Me.TxtName = ""
Me.TxtType = ""
Me.ChkActive = -1
Me.LblActive.Visible = True
Me.TxtWorth = ""
Me.TxtExp = Date
Me.TxtAmount.Visible = False
Me.Label37.Visible = False
Me.TxtPercent.Visible = False
Me.Label38.Visible = False
ElseIf Me.TxtWorth = "Percent" Then
Me.CommandHide.SetFocus
Me.TxtStatus = "SAVED"
Me.TxtID = Nz(DMax("[PaymentNameID]", "PayName"), 0) + 1
Dim PSQL As String
DoCmd.SetWarnings False
PSQL = "INSERT INTO PayName " & _
"(PaymentNameID,PaymentName,PaymentType,ExpirationDate,Active, " & _
"CouponType,CouponWorth,CouponPercent) " & _
"Values(" & Forms!CouponNames!TxtID & ", " & _
"'" & Forms!CouponNames!TxtName & "', " & _
"" & 3 & ", " & _
"" & Format(Forms!CouponNames![TxtExp],
"\#mm\/dd\/yyyy\#") & ", " & _
"" & Forms!CouponNames![ChkActive] & ", " & _
"" & Forms!CouponNames!TxtType & ", " & _
"'" & "Percent" & "', " & _
"'" & Forms!CouponNames!TxtPercent & "')"
DoCmd.RunSQL (PSQL)
DoCmd.SetWarnings True
Me.ListCoupons.Requery
Me.TxtStatus = ""
Me.TxtID = ""
Me.TxtName = ""
Me.TxtType = ""
Me.ChkActive = -1
Me.LblActive.Visible = True
Me.TxtWorth = ""
Me.TxtAmount.Visible = False
Me.Label37.Visible = False
Me.TxtPercent.Visible = False
Me.Label38.Visible = False
End If
ElseIf Me.TxtAction = 1 Then
If Me.TxtWorth = "Dollar" Then
Me.CommandHide.SetFocus
Dim DollUpSQL As String
DoCmd.SetWarnings False
DollUpSQL = "UPDATE PayName SET PayName.PaymentName =
Forms!CouponNames!TxtName, " & _
"PayName.Active = Forms!CouponNames!ChkActive, " & _
"PayName.CouponType = Forms!CouponNames!TxtType, " & _
"PayName.CouponWorth = Forms!CouponNames!TxtWorth, " & _
"PayName.CouponAmount = Forms!CouponNames!TxtAmount, " & _
"PayName.ExpirationDate = Forms!CouponNames!TxtExp " & _
"WHERE PayName.PaymentNameID = Forms!CouponNames!TxtID;"
DoCmd.RunSQL (DollUpSQL)
DoCmd.SetWarnings True
Me.ListCoupons.Requery
DoCmd.OpenForm "FXMsgInfo"
Forms!FXMsgInfo!TxtMsg = "UPDATE SUCCESSFUL"
ElseIf Me.TxtWorth = "Percent" Then
Me.CommandHide.SetFocus
Dim PerUpSQL As String
DoCmd.SetWarnings False
PerUpSQL = "UPDATE PayName SET PayName.PaymentName =
Forms!CouponNames!TxtName, " & _
"PayName.Active = Forms!CouponNames!ChkActive, " & _
"PayName.CouponType = Forms!CouponNames!TxtType, " & _
"PayName.CouponWorth = Forms!CouponNames!TxtWorth, " & _
"PayName.CouponPercent = Forms!CouponNames!TxtPercent,
" & _
"PayName.ExpirationDate = Forms!CouponNames!TxtExp " & _
"WHERE PayName.PaymentNameID = Forms!CouponNames!TxtID;"
DoCmd.RunSQL (PerUpSQL)
DoCmd.SetWarnings True
Me.ListCoupons.Requery
DoCmd.OpenForm "FXMsgInfo"
Forms!FXMsgInfo!TxtMsg = "UPDATE SUCCESSFUL"
End If
End If
End Sub