Compile Error When Programming a Form

lgollner

New Member
Joined
Nov 21, 2007
Messages
4
Hello

I have written some coding to program a form I have developed. All works fine until the last piece of coding which should clear the form fields for use by the next user. This is the string of text

If MsgBox("Clear the Form?", vbYesNo + vbQuestion, "Employee Form") = vbYes Then frmEmployee.InitializeMe.Repaint

I keep getting an error message but I am not sure what I have written incorrectly in this line. The error reads "Method or Data Member not Found" I am not sure what this means. Can anyone provide some clarification or a correction to my string of text.

The Whole piece of coding reads:

Private Sub cmdAdd_Click()
'This Procedure copies the data from the form into the worksheet

'find the row after the end of the data
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select

'enter employee number, first name, and last name
ActiveCell.Value = txtEmployeeNumber.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = txtFirstName.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = txtLastName.Text

'enter date of birth as a date and format it
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = DateValue(txtDOB.Text)
Selection.NumberFormat = "d-mmm-yy"

'enter the age
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "=(INT(TODAY()-" & _
ActiveCell.Offset(0, -1).Address_(RowAbsolute:=False, ColumnAbsolute:=False) & ")/365.25)"
Selection.NumberFormat = "#,##0"

'enter the region that is selected
ActiveCell.Offset(0, 1).Select
If optRegion1 Then ActiveCell.Value = "North"
If optRegion2 Then ActiveCell.Value = "South"

'enter the department that is displayed in the box
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = _
cboDepartment.List(cboDepartment.ListIndex)

'enter the Gross Pay
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Val(txtGrossPay.Text)
Selection.NumberFormat = "$#,##0"

'enter the Tax
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Val(txtTax.Text)
Selection.NumberFormat = "$#,##0"

'enter a formula for net pay
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "=" & ActiveCell.Offset(0, -2).Address(RowAbsolute:=False, ColumnAbsolute:=False) & "-" & ActiveCell.Offset(0, -1).Address(RowAbsolute:=False, ColumnAbsolute:=False)

'offer to clear the form when done
If MsgBox("Clear the Form?", vbYesNo + vbQuestion, "Employee Form") = vbYes Then frmEmployee.InitializeMe.Repaint
End If

End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
There is no InitializeMe event/method for userforms, which is basically what the error message is saying.

What is it you actually want to do?

If you want to reset all the controls to their initial state Repaint won't work.

There are various ways to clear a form, perhaps the easiest one is to close the form then show it again.
Code:
Unload frmEmployee
 
frmEmployee.Show
That will reset all the controls on the form.

If that's not what you want you could loop through all the controls and only reset the ones you want.

For that you would need to have some way of identifying the controls you want to reset, and maybe even how different types of controls should be reset.:)
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top