Solved

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

Posted on 2014-09-17
6
390 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

911 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

22 Experts available now in Live!

Get 1:1 Help Now