Stafford
Registered User.
- Local time
- Today, 02:21
- Joined
- Aug 20, 2002
- Messages
- 23
Number checking Code to ensure user input is honest
I have a Form that my users enter data into that essentially tells me how much work they have done.
The Data (PWRA Number) is a 10 Digit number that is always generated from a 3rd Party Program. It is generated with Zeros 1st.
These PWRAs Numbers are unique to the Branch Number that they were generated from. When the User completes a PWRA they then enter the numbers into my form, which performs a simple calculation and gives me a total of the PWRAs that they did in that branch.
I setup my key fields to be linked in this Fashion
Branch Number
1st PWRA Number
Last PWRA Number
So I have 3 Linked. When I had originally conceived of this I thought this would stop duplication.
The Problem is:
If the Branch number =1 the 1st PWRA =1 and the Last PWRA =1 then my unique number is 111. OK
However if the Branch Number =1 the 1st =1 and the last PWRA =2 The Unique Number is 112, but the 1st PWRA got counted again. Which of course is a duplicate and therefore I get inaccuracy.
Well, laziness has set in and the Users have found me out.
My question, finally is this, how can I code it so that the user can easily enter their numbers without fear of duplication. I am thinking that perhaps I should Search the record set for duplicates, Ahhhh.......... I dunno!
Here is the code I have running now.
--------------------------------------------------------------------------------
Private Sub txtTotal_AfterUpdate()
txtTotal = Val(txtLastPWRANumber) - Val(txtFirstPWRANumber) + 1
End Sub
Private Sub txtFirstPWRANumber_AfterUpdate()
txtFirstPWRANumber = Right("0000000000" & txtFirstPWRANumber, 10)
If Len(Me![txtFirstPWRANumber]) <> 10 Then
MsgBox "PWRA Number must be 10 digits in length"
Exit Sub
End If
End Sub
Private Sub txtLastPWRANumber_AfterUpdate()
txtLastPWRANumber = Right("0000000000" & txtLastPWRANumber, 10) ' Adds prefix of zeros to data entry
If txtFirstPWRANumber = " " Or txtLastPWRANumber = " " Then ' Checks to see if both fields are filled
' Do nothing
Else
txtTotal = Val(txtLastPWRANumber) - Val(txtFirstPWRANumber) + 1 ' Changes ASCII to Numeric and calculates
End If
If Len(Me![txtLastPWRANumber]) <> 10 Then
MsgBox "PWRA Number must be 10 digits in length"
Exit Sub
End If
End Sub
--------------------------------------------------------------------------------
I have a Form that my users enter data into that essentially tells me how much work they have done.
The Data (PWRA Number) is a 10 Digit number that is always generated from a 3rd Party Program. It is generated with Zeros 1st.
These PWRAs Numbers are unique to the Branch Number that they were generated from. When the User completes a PWRA they then enter the numbers into my form, which performs a simple calculation and gives me a total of the PWRAs that they did in that branch.
I setup my key fields to be linked in this Fashion
Branch Number
1st PWRA Number
Last PWRA Number
So I have 3 Linked. When I had originally conceived of this I thought this would stop duplication.
The Problem is:
If the Branch number =1 the 1st PWRA =1 and the Last PWRA =1 then my unique number is 111. OK
However if the Branch Number =1 the 1st =1 and the last PWRA =2 The Unique Number is 112, but the 1st PWRA got counted again. Which of course is a duplicate and therefore I get inaccuracy.
Well, laziness has set in and the Users have found me out.
My question, finally is this, how can I code it so that the user can easily enter their numbers without fear of duplication. I am thinking that perhaps I should Search the record set for duplicates, Ahhhh.......... I dunno!
Here is the code I have running now.
--------------------------------------------------------------------------------
Private Sub txtTotal_AfterUpdate()
txtTotal = Val(txtLastPWRANumber) - Val(txtFirstPWRANumber) + 1
End Sub
Private Sub txtFirstPWRANumber_AfterUpdate()
txtFirstPWRANumber = Right("0000000000" & txtFirstPWRANumber, 10)
If Len(Me![txtFirstPWRANumber]) <> 10 Then
MsgBox "PWRA Number must be 10 digits in length"
Exit Sub
End If
End Sub
Private Sub txtLastPWRANumber_AfterUpdate()
txtLastPWRANumber = Right("0000000000" & txtLastPWRANumber, 10) ' Adds prefix of zeros to data entry
If txtFirstPWRANumber = " " Or txtLastPWRANumber = " " Then ' Checks to see if both fields are filled
' Do nothing
Else
txtTotal = Val(txtLastPWRANumber) - Val(txtFirstPWRANumber) + 1 ' Changes ASCII to Numeric and calculates
End If
If Len(Me![txtLastPWRANumber]) <> 10 Then
MsgBox "PWRA Number must be 10 digits in length"
Exit Sub
End If
End Sub
--------------------------------------------------------------------------------
Last edited: