?
Solved

VB Question - DB Grid

Posted on 1998-08-03
4
Medium Priority
?
283 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 200 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 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