Solved

DataGrid and BeforeUpdate

Posted on 2000-02-23
3
352 Views
Last Modified: 2013-12-26
Hi guys... this is my problem.

In a form I have:
1) One Datagrid, linked to an AdoData control. this works ok.
3) All fields must be filled (IMPORTANT). This is a rule into the table (MDB).
4) A CommandButton.
5) A Sub (CancelAdd) for canceling row adds in the DataGrid.

How this works:
1) When I want to add a registry I press the "Add" CommandButton. This is Ok.
2) To cancel the add before or after filling some or all field I press ESC and the CancelAdd sub is called. This is ok.
3) The CancelAdd Sub do:
DataGrid1.AllowUpdate=False
DataGrid1.AllowAddNew=False
And locate the cursor in another cell. This is Ok too.

But...
4) There is a button to cancel the adding too. When I press it, it calls the same CancelAdd sub, and gives me an error: "Blank fields are not allowed" (because of the table's rules).

The first method (ESC) is called from DataGrid_KeyUp, the second in Command1_Click.

The only one difference I've notice when I click on the button is that the DataGrid1_BeforeUpdate event is activated, but doing it with ESC the BeforeUpdate is not called.

If I Cancel the BeforeUpdate, It wont let me get out of the registry, and the cursor stays in the last row even allowupdate or allowaddnew are disable.

What the hell happens here?
0
Comment
Question by:nfernand
[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
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
jgv earned 50 total points
ID: 2552882
Try refreshing the data control after you cancel the new record:

Private Sub CancelAdd()
   DataGrid1.AllowAddNew = False
   DataGrid1.AllowUpdate = False
   Adodc1.Refresh
End Sub


0
 
LVL 2

Author Comment

by:nfernand
ID: 2554238
Good man.... I've never had imagined something like that.  Thanks.
0
 
LVL 12

Expert Comment

by:jgv
ID: 2554556
No sweat :)

One thing that you have to keep in mind when working with a bound DataGrid is that it is a tool used to display and make limited changes to the contents of an existing recordset. Half the things you can't do with the grid can be done with the recordset, which are then reflected in the grid.

It took me awhile to start 'thinking out of the box' (grid in this case) but it's a trap that's easy to fall into :)
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

738 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