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.