473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Validation Help

20
I have a database that calculates taxes. I have two classes of properties Residential and Commercial. Here is the information

Access:
2003

Fields:
PCC (Text)
ORG-BLDG-VAL-C (Currency)
ORG-BLDG-VAL-R (Currency)

What I want to do is.
If entered a pcc code of 100 to 199, they MUST fill the org-bldg-val-r field.
If entered a pcc code of 300 to 599, they MUST fill the org-bldg-val-c field.
If entered a pcc code of 0?? to 099, they MUST fill both fields fields.

Pcc codes 100-299 are residential properties and 300-599 are commercial class properties. You can’t have a residential code with a commercial value or a commercial code with a residential value. We use 2 different tax rates. (now if the PCC codes starts with Zero (0), then both fields will be used.

Please advise
Jul 16 '07 #1
36 1884
wfma
20
Any help with this would be great!
Jul 17 '07 #2
JKing
1,206 Expert 1GB
Are you using a form to allow the user to enter data? If so what controls?
Or are they entering directly into the table?
Jul 17 '07 #3
wfma
20
Are you using a form to allow the user to enter data? If so what controls?
Or are they entering directly into the table?
They enter the data in to a form. As for controls, not sure what you mean?
Jul 17 '07 #4
JKing
1,206 Expert 1GB
By controls I mean the names of any textboxes or combo boxes that the user would be using to input the data.
Jul 17 '07 #5
wfma
20
By controls I mean the names of any textboxes or combo boxes that the user would be using to input the data.
Yes, they have some drop down boxes.
Jul 17 '07 #6
JKing
1,206 Expert 1GB
Okay, well I'd like to help you code some validation and it would be easier for you to understand if I knew the names of the textboxes and comboboxes so I can refer to your control names in the code.

And explain the layout of your form too. Does the user select a PCC value from a combo box? Then enter a commercial rate or residential rate into a text box? Is there a button that saves all this to the database?
Jul 17 '07 #7
wfma
20
Hmmm...

The fields that I inquiring about are not combo boxes, they are just regular database fields.

If you look at the top posting, you can see the field names and what kind of fild they are

PCC (Text)
ORG-BLDG-VAL-C (Currency)
ORG-BLDG-VAL-R (Currency)

They hand entere the pcc, both rates and values.
Jul 17 '07 #8
JKing
1,206 Expert 1GB
Yes, I understand those are your fields. I want to know about your form though that is being used to input new data. It's my understanding that the user enters a pcc code and based on the range you want to force them to fill in residential rate commercial rate or both. You mentioned that you were using drop downs. Which fields are being represented by the drop downs? Is there a textbox that they enter the residential/commercial values into?
Jul 17 '07 #9
wfma
20
Yes, I understand those are your fields. I want to know about your form though that is being used to input new data. It's my understanding that the user enters a pcc code and based on the range you want to force them to fill in residential rate commercial rate or both. You mentioned that you were using drop downs. Which fields are being represented by the drop downs? Is there a textbox that they enter the residential/commercial values into?
I only use one Drop Down (action-code) I use this field for sorting and grouping my reports only.

The fields org-bldg-val-r and org-bldg-val-c are both text boxes. Depending on the pcc, the user will add the building value in the right box
Jul 17 '07 #10
JKing
1,206 Expert 1GB
Just a few more things. Is it a bound form that is being used to edit and add records? Or is it a simple form with unbound textboxes used for the sole purpose of adding records?
Jul 17 '07 #11
wfma
20
Just a few more things. Is it a bound form that is being used to edit and add records? Or is it a simple form with unbound textboxes used for the sole purpose of adding records?
This form is used to add records only, I have other forms that are used to edit.

I have a form that I use as a menu, When you click on the button to add a record, it run a macro:
Goto Record - New
Open Form - Database mode: Add
Jul 17 '07 #12
wfma
20
Hellooooooooooo, are you still here?
Jul 18 '07 #13
JKing
1,206 Expert 1GB
Hi, because of the complexity of your validation I don't think this can be acheived using the validation rules for table fields.

Here's something you can try adding to the before update event of your form. From the information you've given me I'm assuming you're using a form that is bound to your table and has the data entry property set to yes. This will force the user to enter the proper values depending on the entered pcc code. Also it will catch if they entered an improper value and prompt them to remove it.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  
  3.     Dim strError As String 'Used to format a friendly message to user
  4.     Dim blnError As String
  5.  
  6.     blnError = False
  7.     strError = "Please fix the following:" & vbCrLf
  8.  
  9.     'Residential PCCs
  10.     If Me.PCC >= 100 And Me.PCC <= 299 Then
  11.         If IsNull(Me.[org-bldg-val-r]) Then
  12.             blnError = True
  13.             strError = strError & "You must enter a residential value!" & vbCrLf
  14.         ElseIf Not IsNull(Me.[org-bldg-val-c]) Then
  15.             blnError = True
  16.             strError = strError & "Residential PCCs cannot have commercial values!" & vbCrLf
  17.         End If
  18.     'Commercial PCCs
  19.     ElseIf Me.PCC >= 300 And Me.PCC <= 599 Then
  20.         If IsNull(Me.[org-bldg-val-c]) Then
  21.             blnError = True
  22.             strError = strError & "You must enter a commercial value!" & vbCrLf
  23.         ElseIf Not IsNull(Me.[org-bldg-val-r]) Then
  24.             blnError = True
  25.             strError = strError & "Commercial PCCs cannot have residential values!" & vbCrLf
  26.         End If
  27.     'Both
  28.     ElseIf Me.PCC <= 99 Then
  29.         If IsNull(Me.[org-bldg-val-r]) Then
  30.             blnError = True
  31.             strError = strError & "You must enter a residential value!" & vbCrLf
  32.         End If
  33.         If IsNull(Me.[org-bldg-val-c]) Then
  34.             blnError = True
  35.             strError = strError & "You must enter a commercial value!" & vbCrLf
  36.         End If
  37.     'PCC entered is out of range
  38.     Else
  39.         blnError = True
  40.         strError = strError & "PCC is out of range."
  41.     End If
  42.  
  43.     'If something was wrong then cancel the action and display the problems
  44.     If blnError Then
  45.         Cancel = True
  46.         MsgBox strError, vbOKOnly + vbCritical, "Error!"
  47.     End If
  48. End Sub
  49.  
Let me know if this is what you were looking if not I can try and work something else out or one of the other experts might.
Jul 18 '07 #14
wfma
20
Hmmmm, it seems to work, but I'm getting an error. I think I know why:

The fields org-bldg-val-c and org-bldg-val-c by default have a zero (o) in them. The 0's have to be in them for the setvalue macro to work.

I need to change to isnull statement to >0, When I did that, I got an error in the complier?

also, No matter what the pcc code is, if both fields have a ZERO, then that is ok.
Jul 18 '07 #15
JKing
1,206 Expert 1GB
Here I modified it. It should be fine with zeros now and if the user removes the zero from the wrong textbox it will replace it before inserting to remove nulls.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  
  3.     Dim strError As String 'Used to format a friendly message to user
  4.     Dim blnError As String
  5.  
  6.     blnError = False
  7.     strError = "Please fix the following:" & vbCrLf
  8.  
  9.     'Residential PCCs
  10.     If Me.PCC >= 100 And Me.PCC <= 299 Then
  11.         If IsNull(Me.[org-bldg-val-r]) Then
  12.             blnError = True
  13.             strError = strError & "You must enter a residential value!" & vbCrLf
  14.         End If
  15.         If Me.[org-bldg-val-c] > 0 Then
  16.             blnError = True
  17.             strError = strError & "Residential PCCs cannot have commercial values!" & vbCrLf
  18.         ElseIf IsNull(Me.[org-bldg-val-c]) Then
  19.             Me.[org-bldg-val-c] = 0
  20.         End If
  21.     'Commercial PCCs
  22.     ElseIf Me.PCC >= 300 And Me.PCC <= 599 Then
  23.         If IsNull(Me.[org-bldg-val-c]) Then
  24.             blnError = True
  25.             strError = strError & "You must enter a commercial value!" & vbCrLf
  26.         End If
  27.         If Me.[org-bldg-val-r] > 0 Then
  28.             blnError = True
  29.             strError = strError & "Commercial PCCs cannot have residential values!" & vbCrLf
  30.         ElseIf IsNull(Me.[org-bldg-val-r]) Then
  31.             Me.[org-bldg-val-r] = 0
  32.         End If
  33.     'Both
  34.     ElseIf Me.PCC <= 99 Then
  35.         If IsNull(Me.[org-bldg-val-r]) Then
  36.             blnError = True
  37.             strError = strError & "You must enter a residential value!" & vbCrLf
  38.         End If
  39.         If IsNull(Me.[org-bldg-val-c]) Then
  40.             blnError = True
  41.             strError = strError & "You must enter a commercial value!" & vbCrLf
  42.         End If
  43.     'PCC entered is out of range
  44.     Else
  45.         blnError = True
  46.         strError = strError & "PCC is out of range."
  47.     End If
  48.  
  49.     'If something was wrong then cancel the action and display the problems
  50.     If blnError Then
  51.         Cancel = True
  52.         MsgBox strError, vbOKOnly + vbCritical, "Error!"
  53.     End If
  54. End Sub
  55.  
Jul 18 '07 #16
wfma
20
Wow, that was fast. Thanks.

Well, It worked I think, But, when I add the record, I get a msg box saying:

You can't go to the specified record.

???
Jul 18 '07 #17
JKing
1,206 Expert 1GB
Are you clicking a button or something to add a record? Are any other events or code being executed?
Jul 18 '07 #18
wfma
20
Are you clicking a button or something to add a record? Are any other events or code being executed?
Yes, I used the button wisard ,to creat a add record button.
Jul 18 '07 #19
wfma
20
here is all of the codes that are running: On-Click

Private Sub enter_add_new_Click()
On Error GoTo Err_enter_add_new_Click


DoCmd.GoToRecord , , acNewRec

Exit_enter_add_new_Click:
Exit Sub

Err_enter_add_new_Click:
MsgBox Err.Description
Resume Exit_enter_add_new_Click

End Sub
Private Sub enter_dup_record_Click()
On Error GoTo Err_enter_dup_record_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append

Exit_enter_dup_record_Click:
Exit Sub

Err_enter_dup_record_Click:
MsgBox Err.Description
Resume Exit_enter_dup_record_Click

End Sub
Private Sub Command124_Click()
On Error GoTo Err_Command124_Click


DoCmd.Close

Exit_Command124_Click:
Exit Sub

Err_Command124_Click:
MsgBox Err.Description
Resume Exit_Command124_Click

End Sub
Private Sub Command137_Click()
On Error GoTo Err_Command137_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append

Exit_Command137_Click:
Exit Sub

Err_Command137_Click:
MsgBox Err.Description
Resume Exit_Command137_Click

End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim strError As String 'Used to format a friendly message to user
Dim blnError As String

blnError = False
strError = "Please fix the following:" & vbCrLf

'Residential PCCs
If Me.pcc >= 100 And Me.pcc <= 299 Then
If IsNull(Me.[org-bldg-val-r]) Then
blnError = True
strError = strError & "You must enter a residential value!" & vbCrLf
End If
If Me.[org-bldg-val-c] > 0 Then
blnError = True
strError = strError & "Residential PCCs cannot have commercial values!" & vbCrLf
ElseIf IsNull(Me.[org-bldg-val-c]) Then
Me.[org-bldg-val-c] = 0
End If
'Commercial PCCs
ElseIf Me.pcc >= 300 And Me.pcc <= 599 Then
If IsNull(Me.[org-bldg-val-c]) Then
blnError = True
strError = strError & "You must enter a commercial value!" & vbCrLf
End If
If Me.[org-bldg-val-r] > 0 Then
blnError = True
strError = strError & "Commercial PCCs cannot have residential values!" & vbCrLf
ElseIf IsNull(Me.[org-bldg-val-r]) Then
Me.[org-bldg-val-r] = 0
End If
'Both
ElseIf Me.pcc <= 99 Then
If IsNull(Me.[org-bldg-val-r]) Then
blnError = True
strError = strError & "You must enter a residential value!" & vbCrLf
End If
If IsNull(Me.[org-bldg-val-c]) Then
blnError = True
strError = strError & "You must enter a commercial value!" & vbCrLf
End If
'PCC entered is out of range
Else
blnError = True
strError = strError & "PCC is out of range."
End If

'If something was wrong then cancel the action and display the problems
If blnError Then
Cancel = True
MsgBox strError, vbOKOnly + vbCritical, "Error!"
End If
End Sub
Jul 18 '07 #20
JKing
1,206 Expert 1GB
So clicking the add record button is what causes the "You can't go to the specified record" error?
Jul 18 '07 #21
wfma
20
So clicking the add record button is what causes the "You can't go to the specified record" error?
yep...this is when I get the error
Jul 18 '07 #22
JKing
1,206 Expert 1GB
Open up your form properties and go to the the data tab. Is Allow Additions set to No?
Jul 18 '07 #23
wfma
20
Open up your form properties and go to the the data tab. Is Allow Additions set to No?
Good morning, It is set to yes. Everything is set to yes, but Data Entry is no.

all the settings are by default. I have made no settings
Jul 19 '07 #24
JKing
1,206 Expert 1GB
Does it only happen when you change something on a record and try to skip to a new one? For example your PCC code is 085 and you remove the residential value completely and then click add a new record. The code will force you to stay on that record until you fill in the residential value. This would also cause the "you can't go to the specified record" error.
Jul 19 '07 #25
wfma
20
Does it only happen when you change something on a record and try to skip to a new one? For example your PCC code is 085 and you remove the residential value completely and then click add a new record. The code will force you to stay on that record until you fill in the residential value. This would also cause the "you can't go to the specified record" error.
I entered a blank record, added my tax rate, added a res ppc code, added a res bldg, land, and yard values. then added the new values. Now the commercial values had zeros in them it clicked on the add button, and I get that error that I can't go to the specified record"
Jul 19 '07 #26
wfma
20
Hello.....anyone there?
Jul 20 '07 #27
nico5038
3,080 Expert 2GB
Hmm, very long thread and the use of the BeforeUpdate event isn't the way I approach this.
I allways have a form with an Accept and Cancel button. The Cancel button holds:

IF Me.Dirty then
Me.Undo
End If
Docmd.Close

This will close the form and undo any changes.

The Accept button holds the validation like:

Private Sub btnSave_Click()
Dim txtMessage As String
On Error GoTo Err_btnSave_Click
' init error message
txtMessage = ""
' Check fields in reverse order to set focus to the first
If Not Len(NZ(Me.Description)) > 0 Then
txtMessage = "Description empty ?" & vbCrLf
Me.Description.SetFocus
End If
If Not Len(NZ(Me.Severity)) > 0 Then
txtMessage = "No Severity?" & vbCrLf & txtMessage
Me.Severity.SetFocus
End If
If Not Len(NZ(Me.Type)) = 0 Then
txtMessage = "Recordtype empty ?" & vbCrLf & txtMessage
Me.Type.SetFocus
End If
' Check error found
If Len(txtMessage) > 0 Then
MsgBox txtMessage
Exit Sub
End If

DoCmd.Close

Exit_btnSave_Click:
Exit Sub

Err_btnSave_Click:
MsgBox Err.Description
Resume Exit_btnSave_Click

End Sub

The boolean isn't needed here as the txtMessage can be tested to be filled. Additional advantage is the fact that all errors are mentioned (and can be corrected) in one go.

Idea ?

Nic;o)
Jul 25 '07 #28
nico5038
3,080 Expert 2GB
Dear wfma,

Please post your comments/remarks here in the question instead of using a PersonalMessage, thus the other experts can help/join when I'm not in the house :-)
You PM'd me:
Hi, thanks, How would this help me. Do I make a button and apply this code to it?

Yes, the above code should be placed behind the button named in the Sub so create a button named "btnCancel" and one "btnClick" and place the code in the OnClick event of those buttons.

Nic;o)
Jul 31 '07 #29
wfma
20
OK, I should make a new button, add your code to it, should I also keep the other validation code running on the before update?

I'm not sure why I'm getting confused. I pick up programming easy, but not this time.

:(
Aug 3 '07 #30
nico5038
3,080 Expert 2GB
No, the code replaces the need for the BeforeUpdate code.
This way no "Cancel" has to be issued in the BeforeUpdate as all fields will be OK when the row is updated.
In the [Cancel] button the conditional "Me.Undo" will make sure no errors are saved.

Nic;o)
Aug 3 '07 #31
wfma
20
If I remove the before update code, them how will the validation work?
Aug 6 '07 #32
nico5038
3,080 Expert 2GB
You're then using the standard "Me.Close" mechanism that will update all changed values. This is "custom" behaviour for Access.

When you change data directly in a table, going to the next row triggers the same "custom behaviour".
Closing a form (or navigating to another record) triggers the same behaviour.

By not closing the form (when there's something in the txtMessage string), you're preventing an update with invalid data, but allow the user to press [Cancel] to undo the changes and leave the form.

Clearer ?

Nic;o)
Aug 6 '07 #33
wfma
20
Ok, Baby steps:

I'm going to remove the before update (Yes/No)?

Where do I copy your Close code to?

Where do i copy your Accept Code to?
Aug 7 '07 #34
nico5038
3,080 Expert 2GB
Ok, Baby steps:

I'm going to remove the before update (Yes/No)?
==> Yes, the entire sub

Where do I copy your Close code to?
1) Create button [OK] and
2) Name the button: btnOK
3) In the OnClick event add the code

Where do i copy your Accept Code to?
1) Create button [Cancel]
2) Name the button: btnCancel
3) In the OnClick event add the code

Nic;o)
Aug 7 '07 #35
wfma
20
I should creaat the button(s) on each form correct?
Aug 7 '07 #36
nico5038
3,080 Expert 2GB
Each form where you need to check the correctness needs both buttons.

Nic;o)
Aug 8 '07 #37

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
2
by: Joey P | last post by:
Hi all, I am doing a project for university whereby i have to implement a simple database related to a frozen foods company. I am having some trouble though creating a validation rule for one...
3
by: Rob Meade | last post by:
Hi all, I have a login page which has username and password fields, a login button, and 2 validation controls (one for each field) - currently I have controls to display to the summary if the...
4
by: | last post by:
Hello Guys, I am using the validation controls to validate my data. But the problem is "The page is still being posted to server". I want to get rid of the round trips to server. Are there...
2
by: Dnna | last post by:
I have a table which is bound to an Internet Explorer XML data island. I'm using ASP.NET's client-side validators for an input field in the table. The problem is that if the input fields are in...
5
by: KJ | last post by:
I need help. I have a checkbox and two textboxes on a webform. How can I validation if a person either enters something in the two textboxes OR the checkbox? I tried using a custom validator...
4
by: David Colliver | last post by:
Hi all, I am having a slight problem that hopefully, someone can help me fix. I have a form on a page. Many items on the form have validation controls attached. Also on this form are...
6
by: serge calderara | last post by:
Dear all, I have read that ASP.NET does double user input validation of control when they are place on the page. Once on teh client side and again from server side right ? Could explain how...
6
by: lists | last post by:
Hi all, I am trying to validate an XML file against an XSD schema file within a ..NET C++ program, but the validation doesn't seem to be occuring. My code is listed below. The validation...
2
by: Chad Lupkes | last post by:
Hi everyone, I need help with a simple form validation. The form I'm using has been the target of some spammers, and I'm wondering what else I can do. I have a very simple validation, checking...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.