The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Need Help With Form Validation Please
Posted: 11 Oct 10 10:41 AM
|
I have added some custom code to the AXFormValidate function on the AccountDetails form, and it is working great except for this scenario. If a user enters bad data into my textbox (IUNumber) and then clicks on one of the other functions on the left nav bar (for ex., Contacts) or double clicks on a Contact to open the Contact form, the following happens:
1. Validation Error msgbox: Invalid IU # - Must be a 9 Digit Number 2. Script Error MsgBox:
An error occurred executing active form script (System:Account Detail). Error calling method AXFormValidate
Cannot focus a disabled or invisible window.
When I then click on OK, I am taken to the Contact window. If the user then exits out of SalesLogix, or even returns back to the AccountDetail form, the bad data is saved. How can I keep the user from leaving the AccountDetail form before completing validation? Or at least prevent the bad data from being saved??
Here is my code:
IUNum = edtIUNumber.Text If edtIUNumber.Enabled = True and not isnull(IUNum) and not isempty(IUNum) and not IUNum = "" then If isnumeric(IUNum)= false or len(IUNum) < 9 then msgbox "Invalid IU # - Must be a 9 Digit Number",vbOKOnly,"Validation Error" edtIUNumber.SetFocus AXFormValidate = False End If End If
Thanks!
|
|
|
| |
|
Re: Need Help With Form Validation Please
Posted: 12 Oct 10 9:32 AM
|
Thanks for the reply Mike, but unfortunately this did not work. I don't get the can't set focus error, but the bad data is saved when I click to another form, or when I move to another account. |
|
|
|
Re: Need Help With Form Validation Please
Posted: 12 Oct 10 11:03 AM
|
What version are you on ??
Personally, I'd trap this way before here anyway - create a function (as below) and on the KeyPress event - put the function name in there (CheckForDecimal if you want dec points or CheckForInteger if not).
Sub CheckForInteger (Sender, ByRef Key)
' Check only for numeric values ' If ((Key < 48) or (Key > 57)) and not (Key = 8) and not (Key = 46) and not (Key = 44) then ' Allows "." and "," - but not for integer If ((Key < 48) or (Key > 57)) and not (Key = 8) then Key = 0 End If
End Sub
Sub CheckForDecimal (Sender, ByRef Key)
' Check only for numeric values If ((Key < 48) or (Key > 57)) and not (Key = 8) and not (Key = 46) and not (Key = 44) and not (key = 45) then ' Allows "." and "," - but not for integer ' If ((Key < 48) or (Key > 57)) and not (Key = 8) then Key = 0 End If
End Sub |
|
|
|
Re: Need Help With Form Validation Please
Posted: 12 Oct 10 12:42 PM
|
We're on version 7.5.2
I added your suggested code above to the Key Press event, and that's great for enforcing the entering of numerics only - thanks! However, I also need to verify that the field length is = 9, and I do that in the AXFormValidate function. So I still have the same problem. |
|
|
| |
|
Re: Need Help With Form Validation Please
Posted: 13 Oct 10 9:56 AM
|
Do you mean the AXFormClose subroutine in the form script? If so, I added my code there, but it never got executed when I clicked on the left nav bar or double clicked on a contact. |
|
|
|
Re: Need Help With Form Validation Please
Posted: 13 Oct 10 10:55 AM
|
Here is what is going on:
On the code, you are trying to set focus to the Control, but that may fail depending on what action you have chosen to navigate away from the View.
That failure is causing your code to never reach the "AXFormValidate = False", thus the validation function is not preventing the code from being saved.
My advice:
Move the AXFormValidate = False above the Set focus code. Place an On Error Resume NExt above the SetFocus Code to prevent an error message when the focus cannot be set...
e.g.
If ValidationFails then AxFormValidate = False
' Because the focus code may fail On Error Resume Next MsgBox "An error has ocurred" myControl.SetFocus End If
By adding the OnError Resume next, you allow the function to complete, and the return value to be passed correctly, thus preventing the value from being saved to the DB. Now, you won't be able to retain the focus on the your View, but the data will not be saved.
|
|
|
| |
|
Re: Need Help With Form Validation Please
Posted: 14 Oct 10 9:36 AM
|
Glad to be able to help.
As soon as I read your original Post I quickly realized that the Code was aborting on the Error, thus the Failure on the Validation was never being reached.
|
|
|
|