Setfocus Syntax

Researcher

I.T. Veteran
Local time
Yesterday, 18:37
Joined
Oct 11, 2006
Messages
42
Im attempting to validate an amount field to control the currency that is entered. The data type is currency and the code appears to work fine, however I would like to setfocus to the amount field if the currency entered is 0 or above 200,000. Everything I have tried gives me back the error:

Run-Time error '2108':
You must save the field before you can execute the GoToControl Action, the GoToControl Method, or The SetFocus Method.

Can someone tell me what I am doing wrong? I have attached the code below:

Private Sub Amount_BeforeUpdate(Cancel As Integer)
Dim stramt As String
Dim strtop As String
Dim amtname As String
stramt = "0"
strtop = "200000"
amtname = Amount.Text

If Me.Amount = stramt Then
MsgBox "Jackpot amounts must be greater than zero", vbInformation
Me.Controls(Amount).SetFocus
End If

If Me.Amount > strtop Then
MsgBox "Jackpot amounts are less then 200,000", vbInformation
Me.Controls(Amount).SetFocus
End If

End Sub
 
however I would like to setfocus to the amount field if the currency entered is 0 or above 200,000
This doesn't make sense...to control entries to a field, type the expression you want to use into the validation rule in the table design. That will force a user to enter the value that is "controlled".
 
What version of Access are you developing in?
 
SetFocus Syntax

Answering the second response:

I am using Access 2003

Answering the first response:

It does'nt make sense that I want to setfocus to the "amount" field when the user enters incorrect data and I want to return them to the field to enter correct data? That makes perfect sense to me.

Can anyone point me in the direction to use the setfocus method properly other than the help in VBA and what I have seen in the forumn so far?

Thank You for your help..
 
I found the solution to my problem with the help from Rich and Spacepro, I posted it below:

Private Sub Amount_BeforeUpdate(Cancel As Integer)
Dim stramt As String
Dim strtop As String
Dim amtname As String
stramt = "0"
strtop = "200000"

If Me.Amount = stramt Then
MsgBox "Jackpot amounts must be greater than zero", vbInformation
Cancel = True
Me.Amount.Undo

End If

If Me.Amount > strtop Then
MsgBox "Jackpot amounts are less then 200,000", vbInformation
Cancel = True
Me.Amount.Undo

End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom