Form Validation

B

Blade370

Hi,
I have a form which has a field called school which is occupied by a code
such as G2 etc. I then have another field in which the user enters the course
code. This course code must have begin with the same two characters that
appear in the school field e.g. G2NCAIM
Is there any way to have a validation on that field so that if the first two
characters of the course code do not match then ones in the school field it
will not allow the user to continue onto the next field.

Thank you
 
J

Joan Wild

Consider using the course code without the G2 information in it (since it is redundant). When you need to see the information as a single item (in a query/form/report), you can concatenate the values in the two fields:
[School] & [CourseCode]

That way you allow Access to do the work, and you don't annoy the user.
 
O

Ofer Cohen

On the BeforeUpdate event of the field you can run the code

If Left(Me.[course Code],2) <> Me.[School] Then
MsgBox "The two left chr must be equal to the school name"
Cancel = True ' will stop the process
End If
**********************
BUT, why save it twice, let the user save the school and the course number
without the school, and then you can combine it using a query

Select [course Code],[School],[School] & [course Code] As FullCourseNum From
TableName
 
B

Blade370

Sorry for sounding daft here but how do I enter this code. I pasted it into
the before update event field but recieved an error when I ran it saying that
it could not find the macro.

Thanks

Ofer Cohen said:
On the BeforeUpdate event of the field you can run the code

If Left(Me.[course Code],2) <> Me.[School] Then
MsgBox "The two left chr must be equal to the school name"
Cancel = True ' will stop the process
End If
**********************
BUT, why save it twice, let the user save the school and the course number
without the school, and then you can combine it using a query

Select [course Code],[School],[School] & [course Code] As FullCourseNum From
TableName
--
Good Luck
BS"D


Blade370 said:
Hi,
I have a form which has a field called school which is occupied by a code
such as G2 etc. I then have another field in which the user enters the course
code. This course code must have begin with the same two characters that
appear in the school field e.g. G2NCAIM
Is there any way to have a validation on that field so that if the first two
characters of the course code do not match then ones in the school field it
will not allow the user to continue onto the next field.

Thank you
 
O

Ofer Cohen

When you locate the cursor in the BeforeUpdate event, you'll see a button
with three dots, prss it and select code view,

Put the code in the Sub Section

Private Sub FieldName_BeforeUpdate(Cancel As Integer)
If Left(Me.[course Code],2) <> Me.[School] Then
MsgBox "The two left chr must be equal to the school name"
Cancel = True ' will stop the process
End If

End Sub
--
Good Luck
BS"D


Blade370 said:
Sorry for sounding daft here but how do I enter this code. I pasted it into
the before update event field but recieved an error when I ran it saying that
it could not find the macro.

Thanks

Ofer Cohen said:
On the BeforeUpdate event of the field you can run the code

If Left(Me.[course Code],2) <> Me.[School] Then
MsgBox "The two left chr must be equal to the school name"
Cancel = True ' will stop the process
End If
**********************
BUT, why save it twice, let the user save the school and the course number
without the school, and then you can combine it using a query

Select [course Code],[School],[School] & [course Code] As FullCourseNum From
TableName
--
Good Luck
BS"D


Blade370 said:
Hi,
I have a form which has a field called school which is occupied by a code
such as G2 etc. I then have another field in which the user enters the course
code. This course code must have begin with the same two characters that
appear in the school field e.g. G2NCAIM
Is there any way to have a validation on that field so that if the first two
characters of the course code do not match then ones in the school field it
will not allow the user to continue onto the next field.

Thank you
 
B

Blade370

That worked a treat thanks for the help.

Ofer Cohen said:
When you locate the cursor in the BeforeUpdate event, you'll see a button
with three dots, prss it and select code view,

Put the code in the Sub Section

Private Sub FieldName_BeforeUpdate(Cancel As Integer)
If Left(Me.[course Code],2) <> Me.[School] Then
MsgBox "The two left chr must be equal to the school name"
Cancel = True ' will stop the process
End If

End Sub
--
Good Luck
BS"D


Blade370 said:
Sorry for sounding daft here but how do I enter this code. I pasted it into
the before update event field but recieved an error when I ran it saying that
it could not find the macro.

Thanks

Ofer Cohen said:
On the BeforeUpdate event of the field you can run the code

If Left(Me.[course Code],2) <> Me.[School] Then
MsgBox "The two left chr must be equal to the school name"
Cancel = True ' will stop the process
End If
**********************
BUT, why save it twice, let the user save the school and the course number
without the school, and then you can combine it using a query

Select [course Code],[School],[School] & [course Code] As FullCourseNum From
TableName
--
Good Luck
BS"D


:

Hi,
I have a form which has a field called school which is occupied by a code
such as G2 etc. I then have another field in which the user enters the course
code. This course code must have begin with the same two characters that
appear in the school field e.g. G2NCAIM
Is there any way to have a validation on that field so that if the first two
characters of the course code do not match then ones in the school field it
will not allow the user to continue onto the next field.

Thank you
 
Top