Solved

adodc and a datagrid control

Posted on 2002-06-12
5
321 Views
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..
0
Comment
Question by:TheScottishMonk
5 Comments
 
LVL 5

Expert Comment

by:bob_online
Comment Utility
try dbgGrid.Text
0
 

Author Comment

by:TheScottishMonk
Comment Utility
I tried that it will only read the oldvalue, as in my ex '17'
0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
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
0
 

Author Comment

by:TheScottishMonk
Comment Utility
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."
0
 
LVL 4

Accepted Solution

by:
trkcorp earned 50 total points
Comment Utility
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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now