Solved

DBGrid - copying & pasting records

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

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

708 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

15 Experts available now in Live!

Get 1:1 Help Now