Solved

DBGrid - copying & pasting records

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

914 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

22 Experts available now in Live!

Get 1:1 Help Now