Copy Tabular Data into one Textbox (1 Viewer)

stu_c

Registered User.
Local time
Today, 21:36
Joined
Sep 20, 2007
Messages
489
Hi all
I have a tabular form, when I click a button I need it to copy all the information on that record into two separate text boxes as shown below, any suggestions on how to do this?, I am having real issues trying to get the tabular data copied into a word document so I am hoping by doing this will alleviate a massive issue I am having even as a temporary issue until I solve a proper solution.
Button name: BtnCopyVehicleDetails
 

Attachments

  • AccessHelp.png
    AccessHelp.png
    13.7 KB · Views: 108

Gasman

Enthusiastic Amateur
Local time
Today, 21:36
Joined
Sep 21, 2011
Messages
14,047
You appear to want to copy all the data from the forms records?, not just one record? :unsure:

I would probably use the form's recordsetclone and concatenate the various fields for the textbox values.

Search recordsetclone here as arnelgp uses it a lot and there are lots of examples.

HTH
 

stu_c

Registered User.
Local time
Today, 21:36
Joined
Sep 20, 2007
Messages
489
would record clone do it far each column or would it basically dump everything
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:36
Joined
Sep 21, 2011
Messages
14,047
would record clone do it far each column or would it basically dump everything
You select what you want.? All it ensures is you only process the records for the form.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:36
Joined
May 7, 2009
Messages
19,169
on the Click event of the button:
Code:
Private Sub BtnCopyVehicleDetails_Click()
    Dim strAllMakes As String
    Dim strAllModels As String
    With Me.RecordsetClone
        If Not (.BOF And .EOF) Then
            .MoveFirst
        End If
        Do Until .EOF
            strAllMakes = strAllMakes & vbNewLine & .Fields(Me!txtVehicleMake.ControlSource)
            strAllModels = strAllModels & vbNewLine & .Fields(Me!txtVehicleModel.ControlSource)
            .MoveNext
        Loop
    End With
    If Len(strAllMakes) > 0 Then
        strAllMakes = Replace(strAllMakes, vbNewLine, "", 1, 1)
    End If
    If Len(strAllModels) > 0 Then
        strAllModels = Replace(strAllModels, vbNewLine, "", 1, 1)
    End If
    Me!txtAllVehiclesMakes = strAllMakes
    Me!txtAllVehiclesModels = strAllModels
End Sub
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 21:36
Joined
Jul 9, 2003
Messages
16,245
There's a video demonstration on my website here:-

You should be able to recreate the code by following the video instructions.

If you would like a ready-made sample of the code, let me know and I will explain how you can get a coupon code to download it for free....
 

stu_c

Registered User.
Local time
Today, 21:36
Joined
Sep 20, 2007
Messages
489
Hello Arnelgp
thank you for the below works perfectly!, just as a bit of an upgrade how easy would it be to add a row number in next to each entry, for example, I was looking at having an unbound field on each row using the =1 in control and using RunningSum Property but I do not have that function on my PropertySheet list any sugegstions?

1: Ford
2: BMW
3: Mercedes

1: Focus
2: 330D
3: C250 CDI

on the Click event of the button:
Code:
Private Sub BtnCopyVehicleDetails_Click()
    Dim strAllMakes As String
    Dim strAllModels As String
    With Me.RecordsetClone
        If Not (.BOF And .EOF) Then
            .MoveFirst
        End If
        Do Until .EOF
            strAllMakes = strAllMakes & vbNewLine & .Fields(Me!txtVehicleMake.ControlSource)
            strAllModels = strAllModels & vbNewLine & .Fields(Me!txtVehicleModel.ControlSource)
            .MoveNext
        Loop
    End With
    If Len(strAllMakes) > 0 Then
        strAllMakes = Replace(strAllMakes, vbNewLine, "", 1, 1)
    End If
    If Len(strAllModels) > 0 Then
        strAllModels = Replace(strAllModels, vbNewLine, "", 1, 1)
    End If
    Me!txtAllVehiclesMakes = strAllMakes
    Me!txtAllVehiclesModels = strAllModels
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:36
Joined
May 7, 2009
Messages
19,169
Code:
Private Sub BtnCopyVehicleDetails_Click()
    Dim strAllMakes As String
    Dim strAllModels As String
    Dim i As Integer
    With Me.RecordsetClone
        If Not (.BOF And .EOF) Then
            .MoveFirst
        End If
        Do Until .EOF
            i = i + 1
            strAllMakes = strAllMakes & vbNewLine & i & ": " & .Fields(Me!txtVehicleMake.ControlSource)
            strAllModels = strAllModels & vbNewLine & i & ": " & .Fields(Me!txtVehicleModel.ControlSource)
            .MoveNext
        Loop
    End With
    If Len(strAllMakes) > 0 Then
        strAllMakes = Replace(strAllMakes, vbNewLine, "", 1, 1)
    End If
    If Len(strAllModels) > 0 Then
        strAllModels = Replace(strAllModels, vbNewLine, "", 1, 1)
    End If
    Me!txtAllVehiclesMakes = strAllMakes
    Me!txtAllVehiclesModels = strAllModels
End Sub
 

stu_c

Registered User.
Local time
Today, 21:36
Joined
Sep 20, 2007
Messages
489
Thank you for the below, just out of interest if txtVehicleMake was a combo box with two columns how would I get it to copy column 2 into a text box as currently when I try this it only copy's the bound column

Code:
Private Sub BtnCopyVehicleDetails_Click()
    Dim strAllMakes As String
    Dim strAllModels As String
    Dim i As Integer
    With Me.RecordsetClone
        If Not (.BOF And .EOF) Then
            .MoveFirst
        End If
        Do Until .EOF
            i = i + 1
            strAllMakes = strAllMakes & vbNewLine & i & ": " & .Fields(Me!txtVehicleMake.ControlSource)
            strAllModels = strAllModels & vbNewLine & i & ": " & .Fields(Me!txtVehicleModel.ControlSource)
            .MoveNext
        Loop
    End With
    If Len(strAllMakes) > 0 Then
        strAllMakes = Replace(strAllMakes, vbNewLine, "", 1, 1)
    End If
    If Len(strAllModels) > 0 Then
        strAllModels = Replace(strAllModels, vbNewLine, "", 1, 1)
    End If
    Me!txtAllVehiclesMakes = strAllMakes
    Me!txtAllVehiclesModels = strAllModels
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:36
Joined
May 7, 2009
Messages
19,169
upload a sample and i will show you how, it's very hard to explain.
 

bob fitz

AWF VIP
Local time
Today, 21:36
Joined
May 23, 2011
Messages
4,717
Thank you for the below, just out of interest if txtVehicleMake was a combo box with two columns how would I get it to copy column 2 into a text box as currently when I try this it only copy's the bound column
The column count for combo/listboxes is zero based, so the first column is referenced with NameOfCombo.Column(0) and the second column is referenced with NameOfCombo.Column(1)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:36
Joined
May 7, 2009
Messages
19,169
since you cannot provide a sample, i will provide it.
 

Attachments

  • vehicle.zip
    71.4 KB · Views: 102

Users who are viewing this thread

Top Bottom