Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to copy ONLY certain fields to the clipboard

Status
Not open for further replies.

MHadden

Programmer
May 13, 2001
105
I am trying to copy ONLY the FirstName, LastName, Address & PhoneNumber to the clipboard so that I can paste it into the AlphaNumeric paging system I use at work. Any help you can offer, would be appreciated.
Thanks in Advance,
Michael MichaelHadden@AltaVista.Com
If you give someone a fish, you have given them a meal. If you teach someone to fish, you have given them MANY meals!
 
Why not write a query (or use the QBE grid) to select only those fields?

Andy
 
Sounds great, but I don't know how. My main strength is VBA. I have had very little experience with what you suggested. Would you be able to give any further guidance? Thanks, Michael MichaelHadden@AltaVista.Com
If you give someone a fish, you have given them a meal. If you teach someone to fish, you have given them MANY meals!
 
Depending on the paging system you use then you may well be able to automate this. Using VBA to create a recordset based on an SQL statement (SELECT FirstName, LastName, Address, PhoneNumber FROM YourTableName) that selects only the fields you need and working with the records that it returns.

If you just want to manually paste the records then are you asking how to create a query?

The online help will be of great assistance in either of these.

Andy
 
dim x as string, y as string, z as string, xx as string
x = [Name]
y = [Address]
z = [PhoneNumber]
xx = x & vbTab & y & vbTab & z

Clipboard.SetText xx

Goto receiving record and:

Press Ctrl-V or select Paste from the menu.

SetText copies text onto the Clipboard, replacing whatever text was stored there before. You use SetText like a statement. Its syntax is:

Clipboard.SetText data[, format]

GetText returns text stored on the Clipboard. You use it like a function:

destination = Clipboard.GetText()

mac
 
Mac,
Thanks for taking the time to give such indepth response! I really appreciate it, but, I am getting an error message Run - time 424 object required. I am going to search the MS website, but figured I'd also let you know in case you had any input. Either way I just wanted to say thanks for the help, I think this has set me on the right track. - Michael MichaelHadden@AltaVista.Com
If you give someone a fish, you have given them a meal. If you teach someone to fish, you have given them MANY meals!
 
In case this info helps at all, I wanted to give a little more to go on.
I am using a form. I have found that I can select the record and ctrl C to copy then ctrl V to paste into the other application. The problem with this method is that it not only pastes EVERY field's contents, it Pastes the field names as well. I only need a few fields & no field names to be copied. MichaelHadden@AltaVista.Com
If you give someone a fish, you have given them a meal. If you teach someone to fish, you have given them MANY meals!
 
Error 424 object required is caused by the fact that the clipboard object is only available in VB, not VBA as far as I can see.
Have you tried creating a query yet? From the database window select queries, Click New->Design View, Select your table from the list and use the Query Builder to pick only the fields you need (Double-Click them to put them into the grid).

Andy
 
ps. By online help I meant that which comes with Access and the VBA editor by pressing F1. MSDN is good too, but more difficult to find what you need.

Andy
 
Try this. It outputs the records you need to a text file in comma delimitted format (change to suit your needs).

Private Sub ExportRecords()
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim strRecord As String
Dim FileNum As Integer

Set rst = New ADODB.Recordset

With rst
.ActiveConnection = CurrentProject.Connection
'Modify this SQL statement to suit your needs
.Open Source:="SELECT FirstName, LastName, Address, PhoneNumber FROM YourTableName"

'Get a free file number and open the output file
'for use with comma delimiter format
FileNum = FreeFile
Open "C:\TestOutput.csv" For Output As #FileNum

'Loop through records
Do While Not .EOF
'Initialize string
strRecord = ""
'Loop through fields
For Each fld In .Fields
'Build string from fields
strRecord = strRecord & CStr(fld.Value) & ","
Next fld
'Remove last delimiter from string
strRecord = Left$(strRecord, Len(strRecord) - 1)

'Output record to file
Print #FileNum, strRecord
.MoveNext
Loop 'While Not EOF

Close #FileNum

End With 'rst

Set rst = Nothing

End Sub

You'll need to add error handling, etc.

Andy
 
Andy,
It worked like a champ! Thanks a million for your help. I appreciate both of you guys taking so much of your time to help me!
- Michael MichaelHadden@AltaVista.Com
If you give someone a fish, you have given them a meal. If you teach someone to fish, you have given them MANY meals!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top