Consulting

Results 1 to 5 of 5

Thread: Just VBA - pass info from user form to module?

  1. #1
    VBAX Newbie
    Joined
    Apr 2019
    Posts
    2
    Location

    Just VBA - pass info from user form to module?

    Hello

    I'm pretty new to VBA & I'd like to pass user information from the form to the module - this is what I have so far:

    Very early stages - i understand the processing should be done in the module, not the userform.
    I can't pass the value from the userform to the module:

    The final screen shot shows the message box returning the value aa from the userform when the command button is clicked. However click exit the module message box only shows " _" ww & aa are both missing?
    (aa is in the userform, ww is just a copy of aa)

    vb1.JPGvb2.JPG

    The overall aim is to print a list of drawings overnight.
    The user enters a list of drawing numbers, the application then opens them, prints as pdf's, closes & opens the next.

    This 'early stage' is to pass the input to the form, save the number & build up a list.

    I'm also trying to find help here too:
    https://forums.autodesk.com/t5/inven...n/td-p/8753389


    Regards

    Andrew



  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    855
    Location
    Top of module code...
     Public aa as String
    Public ww as String
    HTH. Dave

  3. #3
    VBAX Newbie
    Joined
    Apr 2019
    Posts
    2
    Location
    Hello Dave

    Thanks for taking a look.
    After some further study i've discovered passing values between the user form & the module isn't straight forward so concentrating on the userform for now.Another discovery is having a variable = variable & looping number is difficult too (impossible?)The idea is for the user to populate the textboxes with drawing numbers - then iterate through them.open idw1, (defer updates on), print to pdf, closenextopen idw2, (defer updates on), print to pdf, closeWhat alternatives are there?



    Attached Images Attached Images

  4. #4
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    855
    Location
    If U put variables as Public at the top of a module (as previously posted) then they are available to the whole project. If just U Dim a variable at the top of a module then it available to all the subs/code in the module. Same for Dim a variable at the top of userform code. I U dim a variable in a sub (or command button code) then it is only available to that sub. "Fullpath" is an XL term that cannot be used as a variable name (at least not without errors). U also have Option Explicit at the top of your code (good) and therefore need to declare (Dim) all of your variables somewhere. What U want to achieve is doable and really should not be that difficult. Dave

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,768
    Location
    I got this from someone here in the forums, but I forgot who gave it to me

    Put a Public Function in the UserForm code and have it return data to the calling macro

     
    Public Function Value_Ret( _
        Optional strTitle As String = "My Custom Input", _
            Optional strPrompt As String = "Enter Something", _
                Optional vntDefault As Variant = vbNullString _
                ) As Variant
     
        With Me
            .Caption = strTitle
            .lblPrompt.Caption = strPrompt
            With .txtInput
                .Value = vntDefault
                .SelStart = 0
                .SelLength = Len(vntDefault)
            End With
            .Show
     
            If Len(.txtInput.Value) > 0 And Not .txtInput.Value = vntDefault Then
                Value_Ret = .txtInput.Value
            Else
                Value_Ret = False
            End If
        End With
        Unload frmInput
    End Function
    

    and call it like this, probably in a standard module

    Option Explicit
    Sub example02()
        MsgBox frmInput.Value_Ret(, , "old text")
    End Sub
    
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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