Solved

Access 2007 how to enter separate lines of address from web into textbox

Posted on 2014-09-17
6
389 Views
Last Modified: 2014-09-19
I'm developing a program to copy name and address information from the web using the clipboard.

I have a textbox on a form for the information.  There is a command button.

Each time the command button is hit, I want the info in the clipboard to appear in the textbox.  

I'm having no problem if the info on the web is in normal name/address format.  I select it all and copy it all to the clipboard and then to the form. It appears in the textbox line by line.  However, if the address lines are separated on the web page, I'd like to copy them one at a time and have each one of the appear as a separate line in the text box ([ipAddrInfo]).

For sake of simplicity, assume that I have a string Dim called HoldClip that the clipboard is properly copied to.  I've been trying to use Allen Browne's InsertAtCursor function, but I cannot seem to get the cursor properly set after each address line.

Private Sub cmdFromWeb_Click()
Dim DataObj As MSForms.DataObject
Set DataObj = New MSForms.DataObject
'Get data from the clipboard.
DataObj.GetFromClipboard
'Get clipboard contents
HoldClip = DataObj.GetText(1)
[ipAddrInfo].SetFocus
If IsNull([ipAddrInfo]) Then
    [ipAddrInfo] = HoldClip
    [ipAddrInfo].SelStart = 0
    [ipAddrInfo].SelStart = Len([ipAddrInfo].Text) + 1
    Exit Sub
End If
 [ipAddrInfo].SelStart = Len([ipAddrInfo].Text) + 1
Call InsertAtCursor(HoldClip)
End Sub

The above code after the first command click enters the correct line of data but with no cursor.  The second address line is appended directly to it...no space, no cursor.
0
Comment
Question by:WFBweb
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:jkaios
ID: 40329304
Did you set the "MultiLine" property of the textbox to True?

Also, could you post the code in the InsertAtCursor() subrountine?
0
 

Author Comment

by:WFBweb
ID: 40329378
Where do I find the MultiLine property?

Public Function InsertAtCursor(strChars As String, Optional strErrMsg As String) As Boolean
On Error GoTo Err_Handler
    'Purpose:   Insert the characters at the cursor in the active control.
    'Return:    True if characters were inserted.
    'Arguments: strChars = the character(s) you want inserted at the cursor.
    '           strErrMsg = string to append any error messages to.
    'Note:      Control must have focus.
    Dim strPrior As String      'Text before the cursor.
    Dim strAfter As String      'Text after the cursor.
    Dim lngLen As Long          'Number of characters
    Dim iSelStart As Integer    'Where cursor is.
   
    If strChars <> vbNullString Then
        With Screen.ActiveControl
            If .Enabled And Not .Locked Then
                lngLen = Len(.Text)
                'SelStart can't cope with more than 32k characters.
                If lngLen <= 32767& - Len(strChars) Then
                    'Remember characters before cursor.
                    iSelStart = .SelStart
                    If iSelStart > 1 Then
                        strPrior = Left$(.Text, iSelStart)
                    End If
                    'Remember characters after selection.
                    If iSelStart + .SelLength < lngLen Then
                        strAfter = Mid$(.Text, iSelStart + .SelLength + 1)
                    End If
                    'Assign prior characters, new ones, and later ones.
                    .Value = strPrior & strChars & strAfter
                    'Put the cursor back where it as, after the new ones.
                    .SelStart = iSelStart + Len(strChars)
                    'Return True on success
                    InsertAtCursor = True
                End If
            End If
        End With
    End If
   
Exit_Handler:
    Exit Function
   
Err_Handler:
Debug.Print Err.Number, Err.Description
    Select Case Err.Number
    Case 438&, 2135&, 2144& 'Object doesn't support this property. Property is read-only. Wrong data type.
        strErrMsg = strErrMsg & "You cannot insert text here." & vbCrLf
    Case 2474&, 2185&       'No active control. Control doesn't have focus.
        strErrMsg = strErrMsg & "Cannot determine which control to insert the characters into." & vbCrLf
    Case Else
        strErrMsg = strErrMsg & "Error " & Err.Number & ": " & Err.Description & vbCrLf
    End Select
    Resume Exit_Handler
End Function
0
 
LVL 12

Expert Comment

by:jkaios
ID: 40329460
If you're using a TextBox control then that's probably why it didn't work.  The TextBox control doesn't have the Value property, so the following line in the InsertAtCursor sub-routine will generate a run-time error.  Please check the Debug window (Immediate window) and see if there is any error printed.

.Value = strPrior & strChars & strAfter    ' will generate an error if the control is a TextBox

Change to:

 .Text = strPrior & strChars & strAfter

Open in new window

0
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

 

Author Comment

by:WFBweb
ID: 40330612
No luck....same result.
The "[ipAddrInfo].SelStart = Len([ipAddrInfo].Text) + 1" doesn't seem to be doing the job it's supposed to do i.e., placing the cursor at the start of the next blank line.  The cursor remains at then end of the line entered.

Even if I manually move the cursor to the start of the next blank line and then bring in the second line InsertAtCursor places it at the end of the first line not on a separate new line.
0
 
LVL 12

Accepted Solution

by:
jkaios earned 500 total points
ID: 40331900
Try commenting out this line as though it didn't exist in your code:
   ' Call InsertAtCursor(HoldClip)

And just replace it with this:
   [ipAddrInfo].Text = [ipAddrInfo].Text & HoldClip


What we're trying to do here is to find where exactly causes the problem.  It the above little tweak works as expected, then we know that the InsertAtCursor() sub-routine is the culprit.
0
 

Author Comment

by:WFBweb
ID: 40333066
This works just fine.  I wonder why InsertAtCursor didn't.  Thanks!

Private Sub cmdFromWeb_Click()
Dim DataObj As MSForms.DataObject
Set DataObj = New MSForms.DataObject
'Get data from the clipboard.
DataObj.GetFromClipboard
'Get clipboard contents
HoldClip = DataObj.GetText(1)
[ipAddrInfo].SetFocus
If IsNull([ipAddrInfo]) Then
    [ipAddrInfo] = HoldClip
    [ipAddrInfo].SelStart = Len([ipAddrInfo].Text) + 1
    Exit Sub
End If
[ipAddrInfo] = [ipAddrInfo] & vbCrLf
[ipAddrInfo].SelStart = Len([ipAddrInfo].Text) + 1
[ipAddrInfo].Text = [ipAddrInfo].Text & HoldClip
End Sub
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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

20 Experts available now in Live!

Get 1:1 Help Now