Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copy/paste one field into another (2003)

    I would like to create an on exit event that copies the contents from one field and pastes into another. I am trying:
    Private Sub Field1_Exit(Cancel As Integer)
    SendKeys "^c"
    DoCmd.GoToControl "Field2"
    SendKeys "^v"
    End Sub

    But that isn't working. Is there any easier way do this? Thank you.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Copy/paste one field into another (2003)

    I wouldn't use the On Exit event for this, for that would transfer the value each time the user leaves the control, even if nothing has changed. I'd use the After Update event instead, and simply set the value of the second control to that of the first one:

    Private Sub Field1_AfterUpdate()
    Me.Field2 = Me.Field1
    End Sub

  3. #3
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copy/paste one field into another (2003)

    Hans,
    I have field2 set as a hyperlink. When I use Me.Field2=Me.Field1 it appears as a hyperlink but the link doesn't work. When I manually copy the contents of field1 into field2 the hyperlink works. Does this change how I should approach this? Thanks...-scott

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Copy/paste one field into another (2003)

    Yes, it is always essential to provide relevant information. If you enter a complete address in Field1 such as http://www.wopr.com, the following will work:
    <code>
    Private Sub Field1_AfterUpdate()
    Me.Field2 = "#" & Me.Field1 & "#"
    End Sub
    </code>
    However, you can't omit the http://.

  5. #5
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copy/paste one field into another (2003)

    Sorry about the lack of detail and thank you for your help...it worked.

  6. #6
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copy/paste one field into another (2003)

    Hans, I think I spoke too soon. Let me try again. Here is what I'm attempting. Field1 is a text field that contains the path of a file location (croject_documentationProject_NameDocument.doc). I would like to be able to launch/open the document (be it word, excel, etc.) by clicking on the field. I setup Field2 is also a text field formatted as a hyperlink. My thinking was to copy the contents of Field1 to Field2 to allow hyperlink access to open the document. Is there a better way to do this? Thank you for your patience and help. -Scott

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Copy/paste one field into another (2003)

    Why don't you use a hyperlink field? That way, the user can right-click it and insert/edit a hyperlink, or left-click it to follow the hyperlink.

    Alternatively, you can put the following code at the top of a standard module:
    <code>
    Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

    Public Const SW_SHOWMAXIMIZED As Long = 3
    </code>
    You can then use either the On Dbl Click event of the text box bound to Field1, or the On Click event of a command button next to the text box to open the document, for example
    <code>
    Private Sub Field1_DblClick(Cancel As Integer)
    Dim lngResult As Long

    lngResult = ShellExecute(hWndAccessApp, "Open", _
    Me.Field1, 0&, 0&, SW_SHOWMAXIMIZED)
    If lngResult <= 32 Then
    MsgBox "Couldn

  8. #8
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copy/paste one field into another (2003)

    Hans, Thanks once again. I used your alternative suggestion which solved the problem. Thank you so much for your help. Take care. - Scott

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •