adodc and a datagrid control

Posted on 2002-06-12
Last Modified: 2012-05-04
I have a dbgrid connected to an adodc. I can't self -errorcheck if the user is adding an incorrect value into the grid. For example I have a integer field called 'Panels' on the grid, now if the user tries to enter a non-numeric field I want to be able to pop up a msgbox saying 'error' and the put the old value back. When I tried to use the 'dbgGrid_BeforeColUpdate' I could only read the oldvalue in the cell, not the one just entered. ex if the old value was '17' and they tried to enter 'bb' I can't pass the value 'bb' into a variable, only 17. It's almost like 'bb' doesn't exist until the adodc enters it into the db. So when the adodc tries to enter the new value into the db it comes up with it's own error message, which I don't want. Please help, thanks in advance..
Question by:TheScottishMonk
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

Expert Comment

ID: 7072871
try dbgGrid.Text

Author Comment

ID: 7072872
I tried that it will only read the oldvalue, as in my ex '17'
LVL 43

Expert Comment

ID: 7072920
You don't have to put the old value back, just set Cancel = True

Private Sub DBGrid1_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
  If NOT IsNumeric(DBGrid1.Text) Then
    Msgbox "Not a number, cancelling",vbExclamation+vbOKOnly
    Cancel = True
  End If
End Sub

Author Comment

ID: 7072949
k I tried that.. what happens is DBGrid1.text still has the value of 17, not 'bb'. So it still considers it a numeric value. This is the error that I get when it tries to enter 'bb' into the db, not sure if it will help or not... 'Multiple-step operation generated errors. Check each status value."

Accepted Solution

trkcorp earned 50 total points
ID: 7073545
try BeforeColumnEdit, EX:

Private Sub DBGrid1_BeforeColEdit(ByVal ColIndex As Integer, ByVal KeyAscii As Integer, Cancel As Integer)
Select Case ColIndex
Case 1
   If KeyAscii < 48 Or KeyAscii > 57 Then
      MsgBox Chr$(KeyAscii) & " is not numeric.)"
      Cancel = True
   End If
End Select
End Sub

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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
Course of the Month11 days, 17 hours left to enroll

623 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