Solved

VB Question - DB Grid

Posted on 1998-08-03
4
252 Views
Last Modified: 2010-05-03
Q.  In an Access table, when you press Ctrl + ',  it copies the value  of the field above to the current field. My question is how we can implement that in a DB Grid in Visual Basic?

Thanks a bunch,

Johnny
0
Comment
Question by:johnny_imam
  • 2
4 Comments
 
LVL 2

Expert Comment

by:shchuka
ID: 1467663
I would simply use the KeyPressed event in the DB Grid.  There you have the row and column numbers of the current cell - substract one to get the previos row - and take the content of that cell...
0
 

Author Comment

by:johnny_imam
ID: 1467664
In the KeyPress event, Row and Col are not sent as parameters. And even if you did know the current row, how would you get the value of the field in the previous row without making the previos row current.
0
 
LVL 1

Accepted Solution

by:
jeffcameron earned 100 total points
ID: 1467665
'This works with the plus key not ctrl '+' I could not get the 'plus key to work with the ctrl key in the keypress or keydown 'events

'grdDataGrid is the name of the grid
'dbSource is the name of the datasource attached to the grid


Private Sub grdDataGrid_KeyPress(KeyAscii As Integer)
Dim colFields As New Collection
Dim i As Integer


Select Case KeyAscii


Case 61:

If dbsource.Recordset Is Nothing Then exit sub

With dbsource.Recordset

If .RecordCount = 0 Then exit sub    

    For i = 0 To .Fields.count - 1
        colFields.Add .Fields(i).Value
    Next i
   
    On Error GoTo errFirstRecord
    .MovePrevious
    On Error GoTo 0
   
    .Edit
   
    For i = 0 To .Fields.count - 1
        .Fields(i).Value = colFields(i + 1)
    Next i
   
    .Update
   
Exit Sub

End With

errFirstRecord:
MsgBox "Cannot perform operation on first record in recordset"
   
Exit Sub

   
End Select





End Sub
0
 

Author Comment

by:johnny_imam
ID: 1467666
Jeff,

This piece of code will not solve my problem. The code above copies all the fields from one row to another. I need the flexibility of just copying one field at a time. Because the data entry person might only wants to copy certain fields. When I am in a new row, Ctrl + ' should copy the value of the field in the above row to the field in the current row. But do not try to update the current row yet, because the user might not be done inputing  all the fields. I need a solution that will copy the data from the field above to the field in the current row without leaving the current row or updating the current row. Just like in a table in Access.

Thanks.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

861 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