Here's one for fumei,
You recently advised on how best to add a 'Click to Clear" button to my userform.
I obviously misunderstood because it hasn't worked.
The code is included below so that you can see what I have done wrong.
Sorry to be such a nuisance. Your help is appreciated.
greg.
[VBA]Option Explicit
Private Sub ClickToFinish_Click()
Dim varCheck
varCheck = IsNumeric(txtAmount.Text)
If varCheck = True Then
Call FillABookmark("Amount", txtAmount.Text)
Else
MsgBox "Amount does not appear to be properly numeric. " & _
"Please re-enter."
txtAmount.Text = ""
txtAmount.SetFocus
Exit Sub
End If
varCheck = IsNumeric(txtRate.Text)
If varCheck <> True Then ' is NOT numeric
If txtRate.Text = "" Then
MsgBox "Interest rate is blank. Please input a numeric entry."
txtRate.SetFocus
Exit Sub
Else
MsgBox "Interest is not numeric. Please input a numeric entry."
txtRate.Text = ""
txtRate.SetFocus
Exit Sub
End If
Else ' it IS numeric
Call FillABookmark("Rate", txtRate.Text)
Call FillABookmark("CostsOnClaim", txtCostsOnClaim.Text)
Call FillABookmark("EntryCosts", txtEntryCosts.Text)
Call FillABookmark("MoniesPaid", txtMoniesPaid.Text)
End If
Call FillABookmark("StartDate", txtStartDate.Text)
Call FillABookmark("EndDate", txtEndDate.Text)
Call FillABookmark("NumDays", DateDiff("d", txtStartDate, txtEndDate))
Call FillABookmark("DailyRate", FormatCurrency((CLng(txtAmount) * CLng(txtRate) / 100) / 365))
ActiveDocument.Fields.Update
Unload Me
End Sub
Private Sub CostsOnClaim_Click()
End Sub
Private Sub Label3_Click()
End Sub
Private Sub UserForm_Click()
End Sub
Option Explicit
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Next
ActiveDocument.Fields.Update
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim oBM As Word.Bookmarks
Set oBM = ActiveDocument.Bookmarks
If oBM("Amount").Range.Text <> "" Then
Me.txtAmount.Text = oBM("Amount").Range.Text
End If
If oBM("Rate").Range.Text <> "" Then
Me.txtRate.Text = oBM("Rate").Range.Text
End If
If oBM("StartDate").Range.Text <> "" Then
Me.txtStartDate.Text = oBM("StartDate").Range.Text
End If
If oBM("EndDate").Range.Text <> "" Then
Me.txtEndDate.Text = oBM("EndDate").Range.Text
End If
If oBM("CostsOnClaim").Range.Text <> "" Then
Me.txtCostsOnClaim.Text = oBM("CostsOnClaim").Range.Text
End If
If oBM("EntryCosts").Range.Text <> "" Then
Me.txtEntryCosts.Text = oBM("EntryCosts").Range.Text
End If
If oBM("MoniesPaid").Range.Text <> "" Then
Me.txtMoniesPaid.Text = oBM("MoniesPaid").Range.Text
End If
Set oBM = Nothing
End Sub
Sub Clear_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
Me.Controls(ctl.Name).Text = ""
ElseIf TypeOf ctl Is CheckBox Then
Me.Controls(ctl.Name).Value = False
ElseIf TypeOf ctl Is ComboBox Then
Me.Controls(ctl.Name).ListIndex = 0
End If
Next
End Sub
[/VBA]