Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2014-09-17
6
392 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

808 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