Private Sub ComboBoxC_due_day_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(Me.ComboBoxC_due_day.Value) Then
MsgBox "Please enter a number between 1 and 31", vbCritical, "Due Day"
Cancel = True
ElseIf Me.ComboBoxC_due_day.Value < 1 Or Me.ComboBoxC_due_day.Value > 31 Then
MsgBox "Please enter a number between 1 and 31", vbCritical, "Due Day"
Cancel = True
End If
End Sub
Private Sub txtC_credit_limit_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(Me.txtC_credit_limit.Value) Then
MsgBox "Please enter a 5-digit number", vbCritical, "Credit Limit Number"
Cancel = True
ElseIf Me.txtC_credit_limit.Value < 0 Then
MsgBox "Please enter a 5-digit number above 0", vbCritical, "Credit Limit Number"
Cancel = True
End If
Me.txtC_credit_limit.Value = Format(Me.txtC_credit_limit.Value, "$#,##0.00")
End Sub
Private Sub txtC_interest_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(Me.txtC_interest.Value) Then
MsgBox "Please enter up to 4-digit number between 0 & 100.0", vbCritical, "Interest Number"
Cancel = True
ElseIf Me.txtC_interest.Value < 0 Or Me.txtC_interest.Value > 100.01 Then
MsgBox "Please enter up to 4-digit number between 0 & 100.0", vbCritical, "Interest Number"
Cancel = True
End If
Me.txtC_interest.Value = Format((Me.txtC_interest.Value) / 100, "#0.00%")
End Sub
Private Sub txtC_interest_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If (KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii = 46) Then
KeyAscii = KeyAscii
Else
KeyAscii = 0
End If
End Sub
Private Sub commandC_close_card_data_form_Click()
Unload Card_Name_UF
End Sub
Private Sub CommandC_continue_Click()
'when we click the enter record button
Dim TargetRow As Integer 'variable for position control
Dim Fullname As String 'full name
Dim UserMessage As String 'variable to configure user message at the end
Fullname = txtC_name & " " & txtC_account 'concatenate name and account for use in code below
'begin check if in 'edit' or 'add' mode
If ShCO01.Range("AN8").Value = "NEW" Then 'in 'new' mode
'begin validaton check 'check' if name already exsits
If Application.WorksheetFunction.CountIf(ShGE01.Range("G9:G109"), Fullname) > 0 Then
MsgBox Fullname & " " & "already exists", 0, "Check"
Exit Sub 'notify user and exit the routine
End If
' end validation check
' check for blanks
If txtC_name.Text = "" Then
txtC_name.BackColor = vbYellow
Cancel = 1
MsgBox "Name Box is empty"
txtC_name.SetFocus
Exit Sub
End If
If txtC_account.Text = "" Then
txtC_account.BackColor = vbYellow
Cancel = 1
MsgBox txtC_name & " Account # Box is empty"
txtC_account.SetFocus
Exit Sub
End If
If txtC_interest.Text = "" Then
txtC_interest.BackColor = vbYellow
Cancel = 1
MsgBox txtC_name & " " & txtC_account & " Interest Rate Box is empty"
txtC_interest.SetFocus
Exit Sub
End If
If txtC_credit_limit.Text = "" Then
txtC_credit_limit.BackColor = vbYellow
Cancel = 1
MsgBox txtC_name & " " & txtC_account & " Credit Limit Box is empty"
txtC_credit_limit.SetFocus
Exit Sub
End If
If ComboBoxC_due_day.ListIndex = -1 Then
ComboBoxC_due_day.BackColor = vbYellow
Cancel = 1
MsgBox txtC_name & " " & txtC_account & " ComboBox for days is empty"
ComboBoxC_due_day.SetFocus
Exit Sub
End If
TargetRow = ShCO01.Range("AN7").Value + 1 'make variable equal to COUNTA formula on worksheet + 1
'end of data entry message
Dim OutPut As Integer
'Example of vbYesNo
OutPut = MsgBox("Name: " & txtC_name & vbCrLf & "Acc. #: " & txtC_account & vbCrLf & "Status: " & ComboBoxc_status & vbCrLf & "Brand: " & ComboBoxc_brand & vbCrLf & "Type: " & ComboBoxc_type & vbCrLf & "Interest Rate: " & txtC_interest & vbCrLf _
& "Credit Limit: " & txtC_credit_limit & vbCrLf & "Due Day: " & ComboBoxC_due_day & "th", vbQuestion + vbYesNoCancel, "Enter Data?")
If OutPut = 6 Then
'Output = 6(yes)
MsgBox "Data has been entered", vbInformation, "Entered"
ElseIf OutPut = 7 Then
'Output = 7(no)
MsgBox "You will now redirected to the edit mode", vbInformation, "Edit Mode"
Exit Sub
Else
'output = 2(cancel)
MsgBox "You will now Exit w/o entering data", vbInformation, "Exit"
Unload Card_Name_UF
End If
Else 'in 'edit'mode
TargetRow = ShCO01.Range("AN9").Value 'make variable equal to value saved in 'controls'
'end of data edit message
MsgBox "Name: " & txtC_name & vbCrLf & "Acc. #: " & txtC_account & vbCrLf & "Status: " & ComboBoxc_status & vbCrLf & "Brand: " & ComboBoxc_brand & vbCrLf & "Type: " & ComboBoxc_type & vbCrLf & "Interest Rate: " & txtC_interest & vbCrLf _
& "Credit Limit: " & txtC_credit_limit & vbCrLf & "Due Day: " & ComboBoxC_due_day & "th", vbOKOnly, "Data edited" 'configure user message for edit entry
'Example of vbYesNo
OutPut = MsgBox("Do you want to enter his data?", vbQuestion + vbYesNo, "Enter Data?")
If OutPut = 6 Then
'Output = 6(yes)
MsgBox "Data has been entered", vbInformation, "Entered"
If OutPut = 7 Then
'Output = 7(no)
MsgBox "You will now redirected to the card intake form to edit or to fully exit (to exit please press 'Cancel' button on that form)", vbInformation, "Edit/Exit"
Exit Sub
End If
End If
End If
'end check if in 'edit' or 'new' mode
'''Begin DATA Entry'''
ShGE01.Range("Data_Start").Offset(TargetRow, 0).Value = TargetRow 'ref
ShGE01.Range("Data_Start").Offset(TargetRow, 1).Value = txtC_name 'name
ShGE01.Range("Data_Start").Offset(TargetRow, 2).Value = txtC_account 'acc. Number
ShGE01.Range("Data_Start").Offset(TargetRow, 3).Value = txtC_name & " " & txtC_account 'fullname concatenate
ShGE01.Range("Data_Start").Offset(TargetRow, 4).Value = ComboBoxc_status
ShGE01.Range("Data_Start").Offset(TargetRow, 5).Value = ComboBoxc_brand
ShGE01.Range("Data_Start").Offset(TargetRow, 6).Value = ComboBoxc_type
ShGE01.Range("Data_Start").Offset(TargetRow, 7).Value = txtC_interest
ShGE01.Range("Data_Start").Offset(TargetRow, 8).Value = txtC_credit_limit
ShGE01.Range("Data_Start").Offset(TargetRow, 9).Value = ComboBoxC_due_day
'''End DATA Entry'''
Unload Card_Name_UF 'close form
'MsgBox Fullname & UserMessage, 0, "Completed" 'display message box (according to mode)
End Sub
Private Sub txtC_account_Enter()
Me.txtC_account.MaxLength = 4
End Sub
Private Sub txtC_account_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim entry As Integer
If Not Me.Visible Then Exit Sub
With Me.txtC_account
.Value = Format(Val(.Value), "0000")
entry = Val(.Value)
End With
If entry = 0 Then
lblc_account = "Please enter a 4-digit number from 0001 To 9999"
Cancel = True
End If
End Sub
Private Sub txtC_account_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If (KeyAscii >= 48 And KeyAscii <= 57) Then
KeyAscii = KeyAscii
Else
KeyAscii = 0
End If
End Sub
Private Sub txtC_name_Change()
txtC_name.Text = Application.Proper(txtC_name.Text)
End Sub
Private Sub txtC_credit_limit_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If (KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii = 46 Or KeyAscii = 36 Or KeyAscii = 44) Then
KeyAscii = KeyAscii
Else
KeyAscii = 0
End If
End Sub
Private Sub txtC_name_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If (KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 And KeyAscii <= 122) Or (KeyAscii = 46) Or (KeyAscii = 45) Or (KeyAscii = 32) Or (KeyAscii = 35) Or (KeyAscii >= 48 And KeyAscii <= 57) Then
KeyAscii = KeyAscii
Else
KeyAscii = 0
End If
End Sub
Private Sub UserForm_Initialize()
Me.Height = 409
Me.Width = 275
End Sub