Keeping cursor from tabbing

  • Thread starter Thread starter AlCamp
  • Start date Start date
A

AlCamp

I have a function that is used by several fields. It works just fine except
that I need the cursor to remain in the field that called the function, so
that the user can reenter a corrected value.

In the AfterUpdate of [SpoolQty] I have...
=CheckNetWeight([SpoolQty])

The Function is as follows...
Public Function CheckNetWeight(CallingCtl As Control)
If NetWeight < 0 Then
' I have a MsgBox here to explain the problem to the user
CallingCtl = 0
'**** need to put code here to keep cursor from advancing to next
field
End If
End Function

I tried Cancel, CancelEvent, Undo, and GoToControl, in various ways, but the
"tab" always executes "after" this function runs.
I think it must have something to do with Cancel, but I can't get the
syntax.

Thanks for any help in advance...
Al Camp
 
Al said:
-----Original Message-----
I have a function that is used by several fields. It works just fine except
that I need the cursor to remain in the field that called the function, so
that the user can reenter a corrected value.

In the AfterUpdate of [SpoolQty] I have...
=CheckNetWeight([SpoolQty])

The Function is as follows...
Public Function CheckNetWeight(CallingCtl As Control)
If NetWeight < 0 Then
' I have a MsgBox here to explain the problem to the user
CallingCtl = 0
'**** need to put code here to keep cursor from advancing to next
field
End If
End Function

I tried Cancel, CancelEvent, Undo, and GoToControl, in various ways, but the
"tab" always executes "after" this function runs.
I think it must have something to do with Cancel, but I can't get the
syntax.

Thanks for any help in advance...
Al Camp
Hi Al,
instead of using the _AfterUpdate() event use the
_BeforeUpdate(). This event has a cancel feature. Then
have your function return either true or false. Have
cancel = the return value...

private sub SpoolQty_BeforeUpdate(cancel)
cancel=CheckNetWeight([SpoolQty])
end sub

Public Function CheckNetWeight(CallingCtl As Control) as
boolean
dim fCancel as boolean
If NetWeight < 0 Then
' I have a MsgBox here to explain the problem to
the user
CallingCtl = 0
fCancel=true
End If
CheckNetWeight=fCancel
End Function

Luck
Jonathan
 
Johnathan,
Thanks a lot for your help. I got the code working.
I had to replace the CallingCtl = 0 with CallingCtl.Undo in order to put
SpoolQty back to it's original value.

I've worked with Access for many years, but there's something that I'm
not grasping about how the Cancel works by using the BeforeUpdate to prevent
an AfterUpdate event.

Private Sub SpoolQty_BeforeUpdate(Cancel As Integer)
CheckNetWeight = fCancel
End Sub

I'm hoping I'm not being a pain here... but...

Could you explain what the above code is "saying". Maybe a brief verbal
explanation of the process that's going on here between Before and After
Update.

Do you know of any available resources where I could read more about the
Cancel process.

Regardless, thanks for all your help. I appreciate it very much.

Al Camp

Jonathan Parminter said:
Al said:
-----Original Message-----
I have a function that is used by several fields. It works just fine except
that I need the cursor to remain in the field that called the function, so
that the user can reenter a corrected value.

In the AfterUpdate of [SpoolQty] I have...
=CheckNetWeight([SpoolQty])

The Function is as follows...
Public Function CheckNetWeight(CallingCtl As Control)
If NetWeight < 0 Then
' I have a MsgBox here to explain the problem to the user
CallingCtl = 0
'**** need to put code here to keep cursor from advancing to next
field
End If
End Function

I tried Cancel, CancelEvent, Undo, and GoToControl, in various ways, but the
"tab" always executes "after" this function runs.
I think it must have something to do with Cancel, but I can't get the
syntax.

Thanks for any help in advance...
Al Camp
Hi Al,
instead of using the _AfterUpdate() event use the
_BeforeUpdate(). This event has a cancel feature. Then
have your function return either true or false. Have
cancel = the return value...

private sub SpoolQty_BeforeUpdate(cancel)
cancel=CheckNetWeight([SpoolQty])
end sub

Public Function CheckNetWeight(CallingCtl As Control) as
boolean
dim fCancel as boolean
If NetWeight < 0 Then
' I have a MsgBox here to explain the problem to
the user
CallingCtl = 0
fCancel=true
End If
CheckNetWeight=fCancel
End Function

Luck
Jonathan
 
Al said:
-----Original Message-----
Johnathan,
Thanks a lot for your help. I got the code working.
I had to replace the CallingCtl = 0 with
CallingCtl.Undo in order to put
SpoolQty back to it's original value.

I've worked with Access for many years, but there's something that I'm
not grasping about how the Cancel works by using the BeforeUpdate to prevent
an AfterUpdate event.

Private Sub SpoolQty_BeforeUpdate(Cancel As Integer)
CheckNetWeight = fCancel
End Sub

I'm hoping I'm not being a pain here... but...

Could you explain what the above code is "saying". Maybe a brief verbal
explanation of the process that's going on here between Before and After
Update.

Do you know of any available resources where I could read more about the
Cancel process.

Regardless, thanks for all your help. I appreciate it very much.

Al Camp

Hi Al Camp,
The example you have above is not the example that I gave
for a solution. Please re-read my post.

As a brief description:
a sub procedure (macro) simply performs instructions
a function procedure performs instructions and can return
a value

' The cancel in the line below is a system parameter
private sub SpoolQty_BeforeUpdate(cancel)

' cancel is assigned the value returned when calling the
function CheckNetWeight (using the value of SpoolQty as a
parameter
cancel=CheckNetWeight([SpoolQty])
end sub

' the function CheckNetWeight is explicitly assigned a
data type boolean.
Public Function CheckNetWeight(CallingCtl As Control) as
boolean
' declaring a boolean variable
dim fCancel as boolean

' assigning the value of the variable fCancel to be
returned by the function CheckNetWeight
CheckNetWeight=fCancel
End Function

Luck
Jonathan
"Jonathan Parminter"
Al said:
-----Original Message-----
I have a function that is used by several fields. It works just fine except
that I need the cursor to remain in the field that
called
the function, so
that the user can reenter a corrected value.

In the AfterUpdate of [SpoolQty] I have...
=CheckNetWeight([SpoolQty])

The Function is as follows...
Public Function CheckNetWeight(CallingCtl As Control)
If NetWeight < 0 Then
' I have a MsgBox here to explain the problem to the user
CallingCtl = 0
'**** need to put code here to keep cursor from advancing to next
field
End If
End Function

I tried Cancel, CancelEvent, Undo, and GoToControl, in various ways, but the
"tab" always executes "after" this function runs.
I think it must have something to do with Cancel, but I can't get the
syntax.

Thanks for any help in advance...
Al Camp
Hi Al,
instead of using the _AfterUpdate() event use the
_BeforeUpdate(). This event has a cancel feature. Then
have your function return either true or false. Have
cancel = the return value...

private sub SpoolQty_BeforeUpdate(cancel)
cancel=CheckNetWeight([SpoolQty])
end sub

Public Function CheckNetWeight(CallingCtl As Control) as
boolean
dim fCancel as boolean
If NetWeight < 0 Then
' I have a MsgBox here to explain the problem to
the user
CallingCtl = 0
fCancel=true
End If
CheckNetWeight=fCancel
End Function

Luck
Jonathan


.
 
Back
Top