Solved

VB Question - DB Grid

Posted on 1998-08-03
4
262 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
[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
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

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

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