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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to paste on focus

Status
Not open for further replies.

zigstick

Technical User
Jun 1, 2006
50
US
Help; trying to write a macro in Access that will open a table, copy a field, then return to an already opened form and paste append the values to the end of the string that is in a memo field. The form where I'm pasting the data would already be opened and the cursor positioned at the end of the existing text when the macro button is pushed. Any suggestions?

thanks much!
 
Don't use a macro but the DLookUp function in VBA.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya zigstick . . .

In case your intent is to [blue]append the entire field[/blue], try this:
Code:
[blue]   Dim db As DAO.Database, rst As DAO.Recordset, Pack As String
   
   Set db = CurrentDb
   Set rst = db.OpenRecordset("[purple][b]tblName[/b][/purple]", dbOpenDynaset)
   
   If rst.BOF Then
      MsgBox "No Records!"
   Else
      Do
         If Pack <> "" Then
            Pack = Pack & ", " & rst![purple][b]FieldName[/b][/purple]
         Else
            Pack = " " & rst![purple][b]FieldName[/b][/purple]
         End If
         
         rst.MoveNext
      Loop Until rst.EOF
      
      Me![purple][b]TextboxName[/b][/purple] = Me![purple][b]TextboxName[/b][/purple] & Pack
   End If
   
   Set rst = Nothing
   Set db = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top