Solved

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

Posted on 2014-09-17
6
393 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

749 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