CursorControl

G

Guest

I am trying set up data validation routines.

This specfic one involves deposits and amounts if there is ck number then i
want to enforce entering an amount. The macro for this is:

'------------------------------------------------------------
' mcrForceDeposit
'
'------------------------------------------------------------
Function mcrForceDeposit()
On Error GoTo mcrForceDeposit_Err

With CodeContextObject
If ((.Deposit Like "*CK*")) Then
DoCmd.GoToControl "depositAmount"
End If
If (.DepositAmount = 0) Then
Beep
MsgBox "Please enter deposit amount.", vbInformation, "There is
an error here."
End If
End With


mcrForceDeposit_Exit:
Exit Function

mcrForceDeposit_Err:
MsgBox Error$
Resume mcrForceDeposit_Exit

End Function
_________

The cursor does NOT go to the deposit field. The msg box pops but the cursor
stays wherever the user clicked.

I want to prevent that, to force a value in this field >0 or cancel the edit.
 
S

Steve Schapel

Sailor Mike,

This is not a macro, it is a VBA procedure.

What event are you running this on?

You have a control named Deposit, right? What is the data that is
entered into this Deposit?
 
G

Guest

No, its a macro. I saved it as VBA so I could post it here. And no, using the
VBA event procedure doesn't help, it still doesn't work.

The Deposit field is text, holds the check number "ck2205" and other
comments as well and no i can't change that, it's a given.

The deposit amount field is currency and defaults to 0.

The macro is attached to the lostfocus event on the deposit amount field.
The idea is that if the user enters "*Ck*" in the deposit field then we have
made out a check and we know the amount and that amount it is >0. So there
should be a value >0 in the deposit amount field. I don't think it matters
but FYI this is a datasheet view and that's a given.

I was hoping to add several of these 'if field1 is this then field2 is this'
statements so i wanted to be sure this one worked - to use as a model.
 
S

Steve Schapel

Sailor Mike,

Ah, ok, I see what you have done. Well, for future reference, while it
is theoretically possible in most cases to convert a macro to VBA, the
resultant VBA is usually very ugly, and in any case reveals very little
about what the initial macro looked like. Better to just give the
details of the macro. Thanks.

Now, we've got a problem which is that you are trying to set the focus
to a control on the Lost Focus event of that same control. The only way
I know how to do this is to have a "dummy" control, set the focus to it,
and then use its Enter event to fire the focus back to the calling one.
But as far as I know, this will not work on a datasheet.

This type of data validation is most often done on the Before Update
event of the form itself. That is what I would recommend.

So, in a macro, if I correctly undertand what you want to do, it would
look like this...

Condition: [Deposit] Like "ck*" And [deposit amount]=0
Action: MsgBox
Message: Deposit amount required
Condition: ...
Action: GoToControl
Control Name: [deposit amount]
 

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

Similar Threads


Top