Prevent form from closing

G

Guest

Hi all i am trying to prevent a form from closing by checking for zero length
in the before update

my msg comes up "you must enter Cable Type"

but the form closes i have tried going to the control but it seems the form
has closed and new msg says there is no control named" Cable Type"
i have Cancel=True but the form still closes


If Len(Me.CableType & "") = 0 Then
GoTo NoCableType
Else
MsgBox "Length of CableType is [" & Len(Me.CableType & "") & "]" &
vbCrLf & _
"...and contains [" & Me.CableType & "]"
End If

ExitHere:
Exit Sub

NoCableType:
MsgBox "Please Enter a Cable Type", vbOKOnly
Cancel = True
GoTo ExitHere
End Sub
 
K

Keith Wilby

Arnie said:
Hi all i am trying to prevent a form from closing by checking for zero
length
in the before update

my msg comes up "you must enter Cable Type"

but the form closes i have tried going to the control but it seems the
form
has closed and new msg says there is no control named" Cable Type"
i have Cancel=True but the form still closes


If Len(Me.CableType & "") = 0 Then
GoTo NoCableType
Else
MsgBox "Length of CableType is [" & Len(Me.CableType & "") & "]" &
vbCrLf & _
"...and contains [" & Me.CableType & "]"
End If

ExitHere:
Exit Sub

NoCableType:
MsgBox "Please Enter a Cable Type", vbOKOnly
Cancel = True
GoTo ExitHere
End Sub

Which event is this code in?

Keith.
 
G

Guest

Before update but i have tried onclose as well same thing happens

Keith Wilby said:
Arnie said:
Hi all i am trying to prevent a form from closing by checking for zero
length
in the before update

my msg comes up "you must enter Cable Type"

but the form closes i have tried going to the control but it seems the
form
has closed and new msg says there is no control named" Cable Type"
i have Cancel=True but the form still closes


If Len(Me.CableType & "") = 0 Then
GoTo NoCableType
Else
MsgBox "Length of CableType is [" & Len(Me.CableType & "") & "]" &
vbCrLf & _
"...and contains [" & Me.CableType & "]"
End If

ExitHere:
Exit Sub

NoCableType:
MsgBox "Please Enter a Cable Type", vbOKOnly
Cancel = True
GoTo ExitHere
End Sub

Which event is this code in?

Keith.
 
G

Guest

seems to work but i also get "The Microsoft Jet database engine could not
find the object". Make sure the object exists and that you spell its name and
the path name correctly"

the form does stay open but that appears between any of the msgbox i call if
there is no data

Ta
Arnie
 
K

Keith Wilby

Arnie said:
seems to work but i also get "The Microsoft Jet database engine could not
find the object". Make sure the object exists and that you spell its name
and
the path name correctly"

the form does stay open but that appears between any of the msgbox i call
if
there is no data

That's not a function of setting cancel = true, I suspect some other issue,
you'll need to do some digging I think.

Keith.
 

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