Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Data vailidation in True DBGrid

Posted on 1998-05-31
1
Medium Priority
?
1,057 Views
Last Modified: 2012-08-14
I have added the codings as follows to check the data in Item No.'s column, if the input item no. is valid, its descripton will be displayed at column 4 and column 5.


Private Sub TDBGridLoanDetails_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
    If ColIndex = 2 Then
        If TDBGridLoanDetails.Text = "" Then
            PostMsgId = 1 'Item no. may not be empty.
            ' Schedule the PostEvent event
            TDBGridLoanDetails.PostMsg PostMsgId
       
            ' The following is used to keep the cell blank
            ' (remove it to restore the old cell value)
            OldValue = ""
       
            ' Cancel the update and keep focus on this cell
            Cancel = True
            Exit Sub
        End If
       
        If ItemAvailable(CLng(TDBGridLoanDetails.Text)) Then
            ShowDescription
        Else
            TDBGridLoanDetails.PostMsg PostMsgId
            OldValue = ""
            Cancel = True
        End If
       
    End If
End Sub

Sub ShowDescription()
    TDBGridLoanDetails.Columns("Model Description").Value = ItemModel
    TDBGridLoanDetails.Columns("Serial No.").Value = ItemSerial
End Sub

However, it's description does not display.
What's the problem ?

I have tried another method, I check the item no. at the KeyPress method of the TDBgrid.

If KeyAscii = vbKeyReturn Or KeyAscii = vbKeyTab Or _
       KeyAscii = vbKeyLeft Or KeyAscii = vbKeyRight Or _
       KeyAscii = vbKeyUp Or KeyAscii = vbKeyDown Then
        'Check Item No.
        If TDBGridLoanDetails.Col = 2 Then
            If TDBGridLoanDetails.Text = "" Then
                PostMsgId = 1 'Item no. may not be empty.
                ' Schedule the PostEvent event
                TDBGridLoanDetails.PostMsg PostMsgId
                Exit Sub
            End If
       
            If ItemAvailable(CLng(TDBGridLoanDetails.Text)) Then
                ShowDescription
            Else
                TDBGridLoanDetails.PostMsg PostMsgId
            End If
        End If
    End If
End Sub


At this case, the item's description can be displayed at column 4 and column 5 when user press [Enter] key but not the arrow keys or the tab key.
0
Comment
Question by:yyjulie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
terencebeh earned 20 total points
ID: 1462163
Try put the similar code in the KeyDown event. Use KeyCode instead of KeyAscii in the KeyDown event.

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question