+ Reply to Thread
Results 1 to 4 of 4

Userform VBA, textbox in a frame - runtime error 438

Hybrid View

  1. #1
    Registered User
    Join Date
    03-04-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    6

    Userform VBA, textbox in a frame - runtime error 438

    I'm a bit of a newbie with Excel VBA but by reading this forum and scouring the internet for example code, I have managed to put together a multipage userform to collect user inputted data and transfer it to a worksheet. The worksheet data is then auto transferred to a Word template to form a report.

    So, Userform1 has multiple named textboxes, eg Textbox71obs, Textbox72obs etc. Each of these textboxes has a default value of "None".
    If a user clicks into any of these textboxes, if the textbox value is "None", then that value disappears and the user can enter their own text. If it's anything other than "None" then the user can still enter the textbox to amend but the original text remains, as planned.

    The following code, which I cobbled together from various internet searches works fine for any textbox on the form, except for the textboxes which are contained within a frame.

    VBA for the Userform1
    Dim TextBoxes() As New Class17
    
    Private Sub UserForm_Initialize()
    Dim Counter As Integer, Obj As Control
    For Each Obj In Me.Controls
    If TypeOf Obj Is MSForms.TextBox Then
    Counter = Counter + 1
    ReDim Preserve TextBoxes(1 To Counter)
    Set TextBoxes(Counter).TextBoxEvents = Obj
    End If
    Next
    Set Obj = Nothing
    End Sub
    Code for Class Module
    Public WithEvents TextBoxEvents As MSForms.TextBox
    
    
    Private Sub TextBoxEvents_MouseDown(ByVal Button As Integer, _
    ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
    
    
    
    If UserForm1.ActiveControl.Value = "None" Then
        UserForm1.ActiveControl.Value = ""
    
    
    End If
    
    
    End Sub

    In the cases of textboxes within a frame, I get a run time error 438 - object doesnt support this property or method at this line of the class module:
    If UserForm1.ActiveControl.Value = "None" Then    UserForm1.ActiveControl.Value = ""
    I'm guessing that its something to do with the 'ActiveControl.value' not relating to a textbox in a frame, but i havent been able to source a solution to rework this line of the code, as yet.
    Any help appreciated!
    Thanks

  2. #2
    Registered User
    Join Date
    03-04-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Userform VBA, textbox in a frame - runtime error 438

    OK, I have been given the solution, and I share below

    If TextBoxEvents.Value = "None" Then 
        TextBoxEvents.Value = "" 
    End If
    instead of using activecontrol.value.

  3. #3
    Forum Contributor
    Join Date
    09-03-2015
    Location
    IE
    MS-Off Ver
    2003 - 2016
    Posts
    258

    Re: Userform VBA, textbox in a frame - runtime error 438

    I have been given the solution
    Was 'given' on Ozgrid

  4. #4
    Registered User
    Join Date
    03-04-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Userform VBA, textbox in a frame - runtime error 438

    sorry for the newbie errors

    I wasnt clear on the rules, and I have been put right on Ozgrid.

    http://www.ozgrid.com/forum/showthread.php?t=196754

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Looping through controls by frame on userform (frame within a frame)
    By njs27 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-27-2015, 10:21 AM
  2. Me.Hide Userform runtime error in Office 365??!!
    By Excel_Runner in forum Office 365
    Replies: 1
    Last Post: 09-07-2014, 05:23 PM
  3. Userform Minimize Button Code Blocking Focus for First TextBox in Frame
    By excelforumkeys in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-14-2014, 12:57 PM
  4. [SOLVED] Runtime error on UserForm
    By DJvdW in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-06-2013, 10:16 AM
  5. RunTime error with UserForm!.Show
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-03-2011, 09:42 AM
  6. Multiple TextBox Input From Runtime Records On Userform
    By bazza88 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-13-2010, 04:48 AM
  7. Insert a Textbox in a Frame during runtime
    By foxbeat in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-15-2007, 06:34 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1