Solved

VB Question - DB Grid

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

724 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