How do I automatically close a form after exiting the last text box on the
form? I have a code that calls a function to check the data on the form and
if the data is OK I would like to close the form. When the line "DoCmd.Close
acForm, "frmProject"" is executed I get the following error code
....This action can't be carried out while processing a form or report event.
Thanks for your help
Private Sub DURATION_Exit(Cancel As Integer)
If IsNull(Me.DURATION) Then
Me.DURATION.BackColor = lngYellow
Y = Y + 1000000
Else
Me.DURATION.BackColor = lngWhite
End If
CheckIt (Y) 'Call teh function CheckIt(Y)
Y = 0
End Sub
Function CheckIt(Y)
Dim ctl As Control
Dim lngYellow As Long
Dim lngWhite As Long
lngYellow = RGB(255, 255, 0)
lngWhite = RGB(248, 248, 255)
Dim X As Boolean
For Each ctl In Forms!frmProject.Controls
With ctl
If .ControlType = acTextBox Or .ControlType = acComboBox Then
If .BackColor = lngYellow Then
X = True
Exit For
End If
End If
End With
Next ctl
If X Then
....
....
....
Else
DoCmd.OpenForm "frmMain", acNormal
Forms!frmMain.cmdImport.SetFocus
DoCmd.Close acForm, "frmProject"
End If
End Function
Jeanette Cunningham - 22 Mar 2008 22:29 GMT
Rafi,
to close the form, users can click the X at top right of the form, or you
can put a close button on the form.
Trying to use an automatic exit from the last text box makes it too hard for
the user.
Users usually like to be able to fill in the text boxes in any order they
wish.
Put a close button on your form.
code its click event using this code ( you can add some code that tells the
button how to get the value of X and work out whether to close the form or
cancel the close.
As I am not exactly sure how your form works and what you are trying to do,
you will probably have more questions on this.
If X Then
> ....
> ....
[quoted text clipped - 4 lines]
> DoCmd.Close acForm, "frmProject"
> End If
Jeanette Cunningham
> How do I automatically close a form after exiting the last text box on the
> form? I have a code that calls a function to check the data on the form
[quoted text clipped - 48 lines]
> End If
> End Function