R
Rafi
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
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