Solved

DBGrid - copying & pasting records

Posted on 1998-09-15
5
306 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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.
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…

856 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