A Second Look at Some Code

S

SCHNYDES

Hi all,

Just need a second look on some code I'm development in a form's LostFocus
event.

I am trying to generate an error message when cetrain options are selected
in the form, Option 1, 2 and 3. Option 1 having a validation rule of the
field BATCHID being 15 chars in length and starting with L. Option 2 having
a rule where BATCHID is no more or less than 15 chars in length. Option 3
having a rule similar to option 1, where BATCHID is 15 chars in length and
begins with F.

The following code I have is from an older version of this DB that I'm
trying to morph, it represents the error messages associated with breaking
the validation rule:

If Me![Options] = 2 Then
If Me!BatchId = "Like '???????????????'" Then
Me!Options.TabStop = False
ElseIf Me![Options] = 1 Then
If Me!BatchId = "Like 'L??????????????'" Then
Me!Options.TabStop = False
ElseIf Me![Options] = 3 Then
If Me!BatchId = "Like 'F??????????????'" Then
Me!Options.TabStop = False
ElseIf Me!BatchId = "Like '???????????????'" Then
MsgBox "Please check to make sure your batch id has 15
characters."
Me!Options.TabStop = False
GoTo Exit_Batch_Number_LostFocus
Else
MsgBox "You have selected the wrong Batch Number Type. Please
select the right type."
Me!Options.TabStop = True
GoTo Exit_Batch_Number_LostFocus
End If

I could use some help making it work properly, any thoughts would be
appreciated.
 
S

SCHNYDES

Updated Code:

If Me![Options] = 2 Then
If Me!BatchId Like "???????????????" Then
MsgBox "Please check to make sure your batch id has 15 characters."
Me!Options.TabStop = False
GoTo Exit_Batch_Number_LostFocus
ElseIf Me![Options] = 1 Then
If Me!BatchId Like "L??????????????" Then
MsgBox "Please check to make sure your BatchID begins with L and is
15 characters."
Me!Options.TabStop = False
GoTo Exit_Batch_Number_LostFocus
ElseIf Me![Options] = 3 Then
If Me!BatchId Like "F??????????????" Then
MsgBox "Please check to make sure your BatchID begins with F and is
15 characters."
Me!Options.TabStop = False
GoTo Exit_Batch_Number_LostFocus
ElseIf Me!BatchId Like "???????????????" Then
MsgBox "Please check to make sure your batch id has 15
characters."
Me!Options.TabStop = False
GoTo Exit_Batch_Number_LostFocus
Else
MsgBox "You have selected the wrong Batch Number Type. Please
select the right type."
Me!Options.TabStop = True
GoTo Exit_Batch_Number_LostFocus
End If
 
G

George Nicholson

Unless I'm missing something:
The only way Option1 code will run is if Option2 code runs.
The only way the Option3 code will run is if the Option1 code runs
(which requires Option2 code to be running).


Maybe restructuring into something like this would help:

Dim fSuccess as Boolean
Dim strMessage as String


If Len(Me!BatchID)<> 15 Then
fSuccess = False
strMessage = "Please check to make sure your batch id has 15
characters."
Else
' BatchID is 15 characters long. Test value per Options.
Select Case Me![Options]
Case 1
If Left(Me!BatchID,1) = "L" Then
fSuccess = True
Else
fSuccess = False
strMessage = "Please check to make sure your BatchID begins
with L"
End If
Case 2
'Any 15 character value is OK.
fSuccess = True
Case 3
If Left(Me!BatchID,1) = "F" Then
fSuccess = True
Else
fSuccess = False
strMessage = "Please check to make sure your BatchID begins
with F"
End If
Case Else
fSuccess = False
strMessage = "Error: Unexpected Options value"
End Select

If fSuccess Then
'Do Something?
Else
MsgBox strMessage
Me!Options.TabStop = False
End If


HTH,
--
George Nicholson

Remove 'Junk' from return address.


SCHNYDES said:
Updated Code:

If Me![Options] = 2 Then
If Me!BatchId Like "???????????????" Then
MsgBox "Please check to make sure your batch id has 15 characters."
Me!Options.TabStop = False
GoTo Exit_Batch_Number_LostFocus
ElseIf Me![Options] = 1 Then
If Me!BatchId Like "L??????????????" Then
MsgBox "Please check to make sure your BatchID begins with L and is
15 characters."
Me!Options.TabStop = False
GoTo Exit_Batch_Number_LostFocus
ElseIf Me![Options] = 3 Then
If Me!BatchId Like "F??????????????" Then
MsgBox "Please check to make sure your BatchID begins with F and is
15 characters."
Me!Options.TabStop = False
GoTo Exit_Batch_Number_LostFocus
ElseIf Me!BatchId Like "???????????????" Then
MsgBox "Please check to make sure your batch id has 15
characters."
Me!Options.TabStop = False
GoTo Exit_Batch_Number_LostFocus
Else
MsgBox "You have selected the wrong Batch Number Type. Please
select the right type."
Me!Options.TabStop = True
GoTo Exit_Batch_Number_LostFocus
End If



SCHNYDES said:
Hi all,

Just need a second look on some code I'm development in a form's
LostFocus
event.

I am trying to generate an error message when cetrain options are
selected
in the form, Option 1, 2 and 3. Option 1 having a validation rule of the
field BATCHID being 15 chars in length and starting with L. Option 2
having
a rule where BATCHID is no more or less than 15 chars in length. Option
3
having a rule similar to option 1, where BATCHID is 15 chars in length
and
begins with F.

The following code I have is from an older version of this DB that I'm
trying to morph, it represents the error messages associated with
breaking
the validation rule:

If Me![Options] = 2 Then
If Me!BatchId = "Like '???????????????'" Then
Me!Options.TabStop = False
ElseIf Me![Options] = 1 Then
If Me!BatchId = "Like 'L??????????????'" Then
Me!Options.TabStop = False
ElseIf Me![Options] = 3 Then
If Me!BatchId = "Like 'F??????????????'" Then
Me!Options.TabStop = False
ElseIf Me!BatchId = "Like '???????????????'" Then
MsgBox "Please check to make sure your batch id has 15
characters."
Me!Options.TabStop = False
GoTo Exit_Batch_Number_LostFocus
Else
MsgBox "You have selected the wrong Batch Number Type. Please
select the right type."
Me!Options.TabStop = True
GoTo Exit_Batch_Number_LostFocus
End If

I could use some help making it work properly, any thoughts would be
appreciated.
 

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