Consulting

Results 1 to 7 of 7

Thread: problem with setfocus after point input in acad

  1. #1
    VBAX Newbie
    Joined
    Aug 2008
    Posts
    4
    Location

    problem with setfocus after point input in acad

    Hello, i have a problem with the part of the code i have paste below

    [vba]If InStr(regel1, "Point:") Then
    'UserForm1.hide
    'returnPnt = ThisDrawing.Utility.GetPoint(, "click het nulpunt van het model aan ")
    'UserForm1.Show
    textbox2.SetFocus
    teller = TextBox2.LineCount[/vba]
    It works so okay.

    But when i remove the ' in front off the 3 other lines it will not function anymore. It will then not set the variabele teller and stop there, it gives a error when i quit the application. The error is that the focus can not be set on textbox2.
    textbox 2 is a part of userform1

    Ow and this is part of more code what should happens as a button in userfomr1 is clicked. (so maybe it goes wrong because of this)
    Last edited by Basp70; 08-22-2008 at 05:15 AM.

  2. #2
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    Welcome, always good to see new users at the forum!

    Are you sure that textbox2 is the name of the object you want to reference?

    What is the exact error message that you're getting?
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  3. #3
    VBAX Newbie
    Joined
    Aug 2008
    Posts
    4
    Location
    Thanks for the warm welcome and the very fast reply.

    The exact error is runtime error '2110'
    can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus.

    When i remove the 3 ' in the lines then first the form is hided, then the program asks me to enter a point in the screen, then the form is popped up again. After that it doesnt do anything anymore. So then i use the X or the cancel button and after that the error is coming up.

    If i don't remove the ' the program just sets the variable teller and goes on. (that is why i think that i have to focus on the textbox2)

    here is the complete subfunction
    [vba]Private Sub CommandButton1_Click()
    Set algemenedata = New DataObject
    algemenedata.GetFromClipboard
    If algemenedata.GetFormat(1) = True Then
    TextBox2.Text = algemenedata.GetText(1)
    Else
    TextBox2.Text = "helemaal foute data, probeer het opnieuw"
    End If

    TextBox2.Text = algemenedata.GetText(1)
    regel1 = GetLine(TextBox2.Text, 1)
    'TextBox2.Text = regel1
    If InStr(regel1, "Point:") Then
    'UserForm1.hide
    'returnPnt = ThisDrawing.Utility.GetPoint(, "click het nulpunt van het model aan ")
    'UserForm1.Show
    TextBox2.SetFocus
    teller = TextBox2.LineCount
    For regelnummer = 1 To teller
    regel1 = GetLine(TextBox2.Text, regelnummer)
    regel2 = Right(regel1, (Len(regel1) - InStr(regel1, "<")))
    xstr = Left(regel2, (InStr(regel2, ",") - 1))
    xr = CDbl(xstr)
    regel2 = Right(regel2, (Len(regel2) - InStr(regel2, ",")))
    ystr = Left(regel2, (InStr(regel2, ",") - 1))
    yr = CDbl(ystr)
    regel2 = Right(regel2, (Len(regel2) - InStr(regel2, ",")))
    zstr = Left(regel2, (InStr(regel2, ">") - 1))
    zr = CDbl(zstr)
    MsgBox (zstr)
    Next regelnummer
    Else
    MsgBox ("Foute data, veld leeggemaakt probeer het opnieuw")
    TextBox2.Text = ""
    End If
    TextBox2.SetFocus

    End Sub[/vba]

    Instead of msgbox (zstr) there will be circles drawn on the coordinates i get out of these text lines which were pasted into the textbox. But first i have to get the zeropoint from which the circle have to be drawn. And that is not functioning at the moment.

  4. #4
    VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,168
    Location
    Hi Basp70,

    I know this is a little lame but move the setfocus before the hide. Then do the hide and after that the show, this way the control already has the focus but the user can't do anything with it until the userform reapears.
    [vba]
    Private Sub CommandButton1_Click()
    Set algemenedata = New DataObject
    algemenedata.GetFromClipboard
    If algemenedata.GetFormat(1) = True Then
    TextBox2.Text = algemenedata.GetText(1)
    Else
    TextBox2.Text = "helemaal foute data, probeer het opnieuw"
    End If

    TextBox2.Text = algemenedata.GetText(1)
    regel1 = GetLine(TextBox2.Text, 1)
    'TextBox2.Text = regel1
    If InStr(regel1, "Point:") Then
    'moved to here set the focus before the hide
    TextBox2.SetFocus
    UserForm1.hide
    returnPnt = ThisDrawing.Utility.GetPoint(, "click het nulpunt van het model aan ")
    UserForm1.Show
    teller = TextBox2.LineCount
    For regelnummer = 1 To teller
    regel1 = GetLine(TextBox2.Text, regelnummer)
    regel2 = Right(regel1, (Len(regel1) - InStr(regel1, "<")))
    xstr = Left(regel2, (InStr(regel2, ",") - 1))
    xr = CDbl(xstr)
    regel2 = Right(regel2, (Len(regel2) - InStr(regel2, ",")))
    ystr = Left(regel2, (InStr(regel2, ",") - 1))
    yr = CDbl(ystr)
    regel2 = Right(regel2, (Len(regel2) - InStr(regel2, ",")))
    zstr = Left(regel2, (InStr(regel2, ">") - 1))
    zr = CDbl(zstr)
    MsgBox (zstr)
    Next regelnummer
    Else
    MsgBox ("Foute data, veld leeggemaakt probeer het opnieuw")
    TextBox2.Text = ""
    End If
    'removed this one
    'TextBox2.SetFocus

    End Sub

    [/vba]

  5. #5
    VBAX Newbie
    Joined
    Aug 2008
    Posts
    4
    Location
    That also didn't do the trick. The workaround what i've used is to make an extra button (GET ZERO POINT)

    [vba]
    Private Sub CommandButton4_Click()
    Me.hide
    returnPnt = ThisDrawing.Utility.GetPoint(, vbCr & "Line Start Point: ")
    CommandButton1.Enabled = True 'button1 (de onderste) activeren
    CommandButton4.Enabled = False 'button4 (de middelste) deactiveren
    Me.Show
    End Sub

    [/vba]
    And this code is working well. But the big question for me still is why didn't it work in the other way. (Could it be that it has to do with the nesting of this function? )

  6. #6

    userform freezing

    try setting the form to non modal (in Properties, set "ShowModal" to false)

  7. #7
    VBAX Newbie
    Joined
    Aug 2008
    Posts
    4
    Location
    Thanks for the last tip that was it.

Posting Permissions

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