Solved

DBGrid - copying & pasting records

Posted on 1998-09-15
5
312 Views
Last Modified: 2010-04-30
I need code or technique to copy a highlighted record (row) from a DBGrid or MSFlexgrid and paste it in the add new record area at the bottom of the grid.

Thanks in advance
0
Comment
Question by:tisd
[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
  • 2
5 Comments
 
LVL 2

Expert Comment

by:dabellei
ID: 1435167
try this  

you need a
1 msflexgrid
1 frame with three command button
        1  cut
        2  copy
        3  paste

Rem  number of msflexgrid1.column
Dim buff0(4) As String

Private Sub Command1_Click()
    Frame1.Visible = False
    If MsgBox("Do you really wnat to delete this row?", 4, "Cut") = 6 Then
        For x = MSFlexGrid1.Row To MSFlexGrid1.Rows - 2
            MSFlexGrid1.Row = x + 1
            MSFlexGrid1.Col = 0
            t0$ = MSFlexGrid1.Text
            MSFlexGrid1.Text = ""
            MSFlexGrid1.Col = 1
            t1$ = MSFlexGrid1.Text
            MSFlexGrid1.Text = ""
            MSFlexGrid1.Col = 2
            t2$ = MSFlexGrid1.Text
            MSFlexGrid1.Text = ""
            MSFlexGrid1.Col = 3
            t3$ = MSFlexGrid1.Text
            MSFlexGrid1.Text = ""
            MSFlexGrid1.Row = x
            MSFlexGrid1.Col = 0
            MSFlexGrid1.Text = t0$
            MSFlexGrid1.Col = 1
            MSFlexGrid1.Text = t1$
            MSFlexGrid1.Col = 2
            MSFlexGrid1.Text = t2$
            MSFlexGrid1.Col = 3
            MSFlexGrid1.Text = t3$
        Next
    End If
End Sub

Private Sub Command2_Click()
    Frame1.Visible = False
    For x = 0 To MSFlexGrid1.Cols - 1
       MSFlexGrid1.Col = x
       buff0(x) = MSFlexGrid1.Text
    Next x
 
End Sub


Private Sub Command3_Click()
    Frame1.Visible = False
    For x = 0 To MSFlexGrid1.Cols - 1
       MSFlexGrid1.Col = x
       MSFlexGrid1.Text = buff0(x)
    Next x
End Sub

Private Sub Form_Load()
    For x = 1 To MSFlexGrid1.Rows - 2
        MSFlexGrid1.Row = x
        MSFlexGrid1.Col = 0
        MSFlexGrid1.Text = x
        MSFlexGrid1.Col = 1
        MSFlexGrid1.Text = x + 2
        MSFlexGrid1.Col = 2
        MSFlexGrid1.Text = x + 3
        MSFlexGrid1.Col = 3
        MSFlexGrid1.Text = x + 4
       
    Next
End Sub


Private Sub MSFlexGrid1_Click()

    MSFlexGrid1.Col = 0
    MSFlexGrid1.ColSel = 3
   
End Sub


Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = 2 Then
       
        If Frame1.Visible = False Then
            Frame1.Visible = True
        End If
       
    End If
End Sub



0
 

Author Comment

by:tisd
ID: 1435168
This solution is a bit too buggy... It doesn't copy the full length of the record
0
 
LVL 2

Expert Comment

by:dabellei
ID: 1435169
Explain what's the bug exactly with the code so i can make correction...
0
 

Author Comment

by:tisd
ID: 1435170
- When you select a record, it only highlights the first 3 fields, it needs to highlight the whole record.

- When you select a portion of a record and click "Copy", the framed controls all disappear, and the contents cannot really be pasted into any other application.
0
 
LVL 3

Accepted Solution

by:
TheAnswerMan earned 20 total points
ID: 1435171
I recommend somthing like this..
Grid1_KeyPress(keyascii as integer)
Dim x as integer
Dim ls_string as string
if Keyascii = 13 then  'if they hit enter.. copy to a new row

  for x = 1 to grid1.cols -1
    grid1.col = x
    ls_string = ls_string & Grid1 & ";"
  next x

  'This will give you a String that is a semi-colon delimited  
  'list of what is in the current row
  grid.row = fi_TheRowToCopyTo  ' the row i want to copy to
  Grid.col = 1
  do while len(ls_string) > 0
    x = instr(ls_string,";")
    grid1 = Left$(ls_string,x-1)
    ls_string = Mid$(ls_string,x+1)
  loop
0

Featured Post

Independent Software Vendors: 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 …
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…

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