DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Validation for Data control event

  1. #1
    Join Date
    May 2006
    Location
    UK
    Posts
    1

    Question Validation for Data control event

    Hi everyone

    I have a strange thing happening within my program and not sure why but perhaps someone has come across this before.

    My program is linked to a database and has command buttons to scroll left, right, EOF and BOF.

    As part of this I have a datacontrol and I have validation set up in the data control valdiation event. Although I think textbox validation is more effective, I have instructions to follow and the validation has to be in the data control validation event.

    Most of the validation works fine, but I have my final else statement not working. If I add this into the program and if I scroll to eof and move back one and then forward again, this does not disable the > and eof command buttons and it brings up a blank record. I then get the message in the validation event.

    When I press ok, I get the error - run time error 3021 no current record.

    This happens whether eof or bof.

    When I click on debug it goes to the datstock.recrdset.edit row

    If I take this code out of the equasion, I don't get any of these problems.
    Any suggestions?
    Validation code I'm using is:


    visual basic code:
    --------------------------------------------------------------------------ElseIf Not IsNumeric(txtField(bdNumberInStock)) Then
    MsgBox "NoInStock must be numeric", vbOKOnly, "NoInStock"
    datStock.Recordset.Edit
    datStock.Recordset.CancelUpdate
    --------------------------------------------------------------------------

    Full code for this event is below

    visual basic code:
    ---------------------------------------------------------

    Private Sub datStock_Validate(Action As Integer, Save As Integer) '
    'Validate records
    If InStr(txtField(bdISBN), " ") Then
    MsgBox "No spaces allowed", vbOKOnly, "ISBN No"
    datStock.Recordset.Edit
    datStock.Recordset.CancelUpdate
    ElseIf Val(txtField(bdCategory)) > 20 Then
    MsgBox "Category must be between 1 and 20", vbOKOnly, "Category"
    datStock.Recordset.Edit
    datStock.Recordset.CancelUpdate
    ElseIf InStr(txtField(bdNumberInStock), " ") Then
    MsgBox "NoInStock does not allow spaces", vbOKOnly, "NoInStock"
    datStock.Recordset.Edit
    datStock.Recordset.CancelUpdate
    ElseIf Not IsNumeric(txtField(bdNumberInStock)) Then
    MsgBox "NoInStock must be numeric", vbOKOnly, "NoInStock"
    datStock.Recordset.Edit
    datStock.Recordset.CancelUpdate

    Else
    cmdAction(2) = True ' update record
    End If

    --------------------------------------------------------------------------------

    Thanks

    Tracey

  2. #2
    Join Date
    Feb 2006
    Posts
    133
    Hi Tracey,

    not sure what the problem is. But I have 1 remark, you can simplify your code:

    Code:
    Select Case True
            Case InStr(txtField(bdISBN), " ")
                MsgBox "No spaces allowed", vbOKOnly, "ISBN No"
            Case Val(txtField(bdCategory)) > 20
                    MsgBox "Category must be between 1 and 20", vbOKOnly, "Category"
            Case InStr(txtField(bdNumberInStock), " ")
                MsgBox "NoInStock does not allow spaces", vbOKOnly, "NoInStock"
            Case Not IsNumeric(txtField(bdNumberInStock))
                MsgBox "NoInStock must be numeric", vbOKOnly, "NoInStock"
            Case Else
                cmdAction(2) = True ' update record
                Exit Sub
        End Select
        
        datStock.Recordset.Edit
        datStock.Recordset.CancelUpdate
    No need to repeat every time the 2 lines.
    Benjamin

Similar Threads

  1. Replies: 2
    Last Post: 11-21-2005, 04:10 PM
  2. Replies: 1
    Last Post: 04-19-2005, 08:03 PM
  3. Replies: 0
    Last Post: 07-25-2002, 10:25 AM
  4. Replies: 0
    Last Post: 10-07-2000, 03:16 AM
  5. Replies: 0
    Last Post: 03-23-2000, 05:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center