On close event Problem?

J

Jon

I have a form for entering data into a table. I put the following vb code On
close event of the form:


Private Sub Form_Close()
Me.CloseButton = True
If Len(Trim$(Me![MachName] & vbNullString)) = 0 Then
MsgBox (" You can not close this Form without Mach. Name ")
Me.MachName.SetFocus
Me.CloseButton = False
ElseIf IsNull(Me.Code) Then
MsgBox (" You can not close this Form without Mach. Code ")
Me.MachName.SetFocus
Me.CloseButton = False
Else
Me.CloseButton = True

End If
End Sub

But the problem is an error that tells "you can not assign a value to this
object "

Can any body correct my code please??
 
K

Ken Sheridan

Use the Unload event not the Close event. The former includes a Cancel
argument whose return value you can set to True if the validation criteria
are not met. Add a line:

Cancel = True

within the If and ElseIf statements.

I'm not quite sure what setting Me.CloseButton to True or False is intended
to achieve, however. You can set a Boolean variable or a control bound to a
Boolean (Yes/No) column to True or False but not a command button (which I'm
assuming is what it is). Unless it’s a toggle button, which would be unusual
for a button to close a form. I think you can simply delete those lines.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top