Adding error messages to this Alphanumeric Generator.

rodvaN

Registered User.
Local time
Today, 11:35
Joined
May 20, 2009
Messages
92
Hello there, I used to have this code for generate fields from Data1 to Data2, like A001 to A005, it would generate A001, A002, A003, A004, A005.
So it works with this code.

Code:
Set db = CurrentDb
Set rs = db.OpenRecordset("Almacenes")
For x = Val(Right(Me!Data1, 3)) To Val(Right(Me!Data2, 3))
rs.AddNew
rs!Almacen = Left(Me!Data1, 1) & String(3 - Len(x), "0") & x
rs.Update
Me.Refresh
Next

---- Now what I wanted to do is add error messages when the final user didnt digit a form like ALPHA,NUMERIC,NUMERIC,NUMERIC.
---- If the Alpha variable not in MAYUS.. then display mayus error.
---- And when the user put on the field data1 A005 and on field data2 A004 that it showed it cant generate lower data.

So far I got this.

Code:
Private Sub Command5_Click()

Dim fAlpha As Integer: Asc (Left(Me!Data1, 1))
Dim fNumeric As Boolean: IsNumeric (Right(Me!Data1, 3))
Dim sAlpha As Integer: Asc (Left(Me!Data2, 1))
Dim sNumeric As Boolean: IsNumeric (Right(Me!Data2, 3))

If (fAlpha < 65) Or (fAlpha > 90) Or _
(sAlpha < 65) Or (sAlpha > 90) Or _
(Not fNumeric) Or (Not sNumeric) Then
MsgBox "Theres been an error, try digit something like.. A001 - A005..", , "buhoruS says:"
Exit Sub
End If

Set db = CurrentDb
Set rs = db.OpenRecordset("Almacenes")
For x = Val(Right(Me!Data1, 3)) To Val(Right(Me!Data2, 3))
rs.AddNew
rs!Almacen = Left(Me!Data1, 1) & String(3 - Len(x), "0") & x
rs.Update
Me.Refresh
Next

End Sub

Could anyone help with this?
 
On the AfterUpdate event of the control Me.Data2

Code:
Sub Data2_AfterUpdate()

If IsNumeric(Right(Me.Data1,3)) Then
   If Val(Right(Me.Data2,3)) < Val(Right(Me.Data1,3)) Then
      'Invalid
   End If
End If

End Sub

This code does not perform any type of validation on the contents of the controls other than the last 3 digits are numeric.

You would need to build in further checks to ensure the code is Annn or is not null

David
 
And How it would be the error If user dont type MAYUS character?
 
And How it would be the error If user dont type MAYUS character?

Forgive my ignorance but what is MAYUS?

David
 
My mistake.. used to that word. I meant CAPS on.
 
access ignores differences between upper and lower case

in the afterupdate event for the FIELD (not the FORM!) just put

myfield=upcase(myfield)

to get any letters consistent (might be ucase, not upcase)
 
Its actually UCase() and LCase() upper and lower
 
Then if I use this it launches an debug..
Code:
Private Sub Data1_AfterUpdate()
Data1 = UCase()
End Sub

So I could do lots of things for displaying messages, but would I be able to change automatically the LCase to UCase on the final table?
 
Code:
Private Sub Data1_AfterUpdate()
If fAlpha = LCase(fAlpha) Then
    MsgBox "You Have to type UPCASE word"
    Data1 = Null
    Me.Data1.SetFocus
End If
    
End Sub

This code I made is wrong, even if i type UPCASE word, it will display the msgbox,null and setfocus..
Anyone knows what Am I doing wrong?
 
Why are you bothering to validate the case mix for the entry when you can simply convert it on the after update event

Me.Field = UCase(Me.Field)

David
 

Users who are viewing this thread

Back
Top Bottom