Solved

VB Question - DB Grid

Posted on 1998-08-03
4
217 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
Comment Utility
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
Comment Utility
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
Comment Utility
'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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now