Solved

DBGrid - copying & pasting records

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

813 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

12 Experts available now in Live!

Get 1:1 Help Now