Solved

ADO DataGrid

Posted on 2003-12-05
7
1,064 Views
Last Modified: 2006-11-17
Hi All,
I have a ADO datagrid, a ADO data control(Adodc1) and an update button on a form.
My problem is that when a selected row on the grid is updated and the recordset is reloaded, the cursurs(or arrow on the grid) always jumps back to the first row of the dataset displayed in the datagrid. I would like the reloaded data (containing the updated record) to be visible in the grid without having to scroll all the way to find the updated record.

I also do not want the updated record to be moved as firstrecord in the dataset.

Anyone have any suggestens?

Thx in Adv.
0
Comment
Question by:MarjonChirill
[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
7 Comments
 
LVL 1

Accepted Solution

by:
carpe-diem earned 250 total points
ID: 9882541
You could use the AbsolutePosition property of the recordset as long as you only update records (as opposed to adding or deleting which will change the number and position of records)

use;
Dim intCurrentRecord As Integer

With Adodc1.Recordset
          intCurrentRecord = .AbsolutePosition
End With

Do your thing here, then after you reload the data

With Adodc1.Recordset
         .AbsolutePosition = intCurrentRecord
End With

0
 
LVL 4

Expert Comment

by:TomLaw1999
ID: 9885656
What code do you have behind the update button?
0
 

Author Comment

by:MarjonChirill
ID: 9885707
Private Sub Update_Click()  
 'Definieer database
    OpenConnection
   
    'Definieer Volgnr
    Dim Volgnr As Long
   
    'Controleer datum velden
    If Not datumCheck(BDatum.Text) Then
        BDatum.BackColor = QBColor(14)
        MsgBox "Please Enter A Valid Date dd-mm-yyyy...", vbInformation
        Exit Sub
    End If
   
    If Not datumCheck(EDatum.Text) Then
        EDatum.BackColor = QBColor(14)
        MsgBox "Please Enter A Valid Date dd-mm-yyyy...", vbInformation
        Exit Sub
    End If
   
    'Controleer tijd
    If Not IsTime(BTijd.Text) Then
        BTijd.BackColor = QBColor(14)
        MsgBox "Please Enter A Valid Time hh:mm:ss...", vbInformation
        Exit Sub
    End If
   
    If Not IsTime(Etijd.Text) Then
        BTijd.BackColor = QBColor(14)
        MsgBox "Please Enter A Valid Time hh:mm:ss...", vbInformation
        Exit Sub
    End If
   
    User = Environ("UserName")
    Volgnr = DataGrid1.Columns(0).CellText(DataGrid1.Bookmark)
   
    'Velden welke toegevoegd moeten worden
    Dim Velden As String
    Velden = "VOLGNUMMER" & ", " & "BEGIN_DATUM"
    Velden = Velden & ", " & "EIND_DATUM"
    Velden = Velden & ", " & "NAAM" & ", " & "SOORT" & ", " & "OORZAAK"
    Velden = Velden & ", " & "OPMERKING" & ", " & "BEPERKING" & ", " & "PMAX"
    Velden = Velden & ", " & "DATUM_LAMU" & ", " & "GEBR_LAMU"
   
    SQL_STATEMENT = " UPDATE BEPERKING"
    SQL_STATEMENT = SQL_STATEMENT & " SET BEGIN_DATUM = " & BDatum.Text & BTijd.Text
    SQL_STATEMENT = SQL_STATEMENT & " SET EIND_DATUM = " & EDatum.Text & Etijd.Text
    SQL_STATEMENT = SQL_STATEMENT & " SET NAAM = " & NaamEenh.Text
    SQL_STATEMENT = SQL_STATEMENT & " SET SOORT = " & SoortCombo1.Text
    SQL_STATEMENT = SQL_STATEMENT & " SET OORZAAK = " & OorzaakCombo2.Text
    SQL_STATEMENT = SQL_STATEMENT & " SET OPMERKING = " & Opmerking(0).Text
    SQL_STATEMENT = SQL_STATEMENT & " SET BEPERKING = " & Beperkingmw.Text
    SQL_STATEMENT = SQL_STATEMENT & " SET PMAX = " & Maxverm.Text
    SQL_STATEMENT = SQL_STATEMENT & " SET DATUM_LAMU = " & Date & Time
    SQL_STATEMENT = SQL_STATEMENT & " SET GEBR_LAMU = " & User
    SQL_STATEMENT = SQL_STATEMENT & " WHERE VOLGNUMMER = " & Volgnr
    cn.Execute SQL_STATEMENT, dbFailOnError
End Sub
-------------------
This is the code. I check some dates, read the username, and capture the key of the record, and then update the database record.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 29

Expert Comment

by:leonstryker
ID: 9904329
Do a

Recordset.Refresh
Recordset.Find = key field

after the you run the update statement.  Why are you using a DataControl?

Leon
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 9904330
Do a

Recordset.Refresh
Recordset.Find = key field

after the you run the update statement.  Why are you using a DataControl?

Leon
0
 

Author Comment

by:MarjonChirill
ID: 9905087
carpe-diem,
It works! Thank you! I will 'accept' your solution.
--------------
Leonstryker,
I tried your statements but I am getting a Run-time error '3001'. (Arguments are of the wrong type..).
To solve the error, I altered the statement to:

'Volgnr being my key field

Dim strVolgnr As String
strVolgnr = Cstr(Volgnr)

'Because Adodc1.Recordset does not have a 'Refresh' property i altered the stement as seen below
DataGrid1.Refresh
Adodc1.Recordset.Find(strVolgnr)

But...still didn't work. I got the same Run-time error '3001'

Anyway Thx for trying to help...
Marjon
0
 

Expert Comment

by:gavakian
ID: 10034371
Gus does anyone know how i declare a global variables and how to exchange pointer to databases between forms.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

726 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