Consulting

Results 1 to 9 of 9

Thread: Solved: How to pass login parameters from a form to a function

  1. #1
    VBAX Regular
    Joined
    Nov 2008
    Posts
    41
    Location

    Solved: How to pass login parameters from a form to a function

    Hi,

    I'd like to have a login screen, where some login information is added, and then use that information in my function.

    For now I've done this:

    Before I login I have this:
    [vba]
    Set LoginForm = New frmLogin
    LoginForm.tbxURL = vUrl
    LoginForm.tbxDomain = vDomain
    LoginForm.tbxProject = vProject
    LoginForm.Show

    vUser = LoginForm.tbxUser
    vUrl = LoginForm.tbxURL
    vProject = LoginForm.tbxProject
    vPassword = LoginForm.tbxPassword
    vDomain = LoginForm.tbxDomain
    [/vba]

    However, how do I make sure that I get back to my procedureonce I press ok, or exit the procedure completely when I press cancel?

    EDIT: If I press the built-in close button my procedure still works, but off course also want action when OK or Cancel is clicked. How do I do this? Exit, close and hide didn't seem to work for me. exit sub also only exits the event, not the sub above it.
    Last edited by Marcke; 12-22-2008 at 09:26 AM.

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi Marcke,

    Speaking only for myself, it is a little unclear as to what you are trying to do as far as exiting a function if Cancel is pressed. I think that attaching an example workbook would help anyone who tries to answer.

    Best Regards,

    Mark

  3. #3
    VBAX Regular
    Joined
    Nov 2008
    Posts
    41
    Location
    I'll try again to explain more clearly:

    I have a function, that extracts values through an API.

    Somewhere in that function I have to get login variables (password, user, domain, project and URL)

    I first had an inputbox, but as there the password is not masked, I'd like to have some kind of form.

    I can show the form within my extract function, but cannot seem to close it and pass variables when enter is pressed, and exit my extract function when cancel is pressed.

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Marcke,

    Here's code based upon your input:

    In a standard module:
    [vba]Option Explicit

    Public bolBailOut as Boolean
    Public strPWord as String, strUser as String, strDomain as String, strProject as String

    Function YourFunction()
    '...statements

    frmExample.Show

    If bolBailOut then Exit Function

    '... other statements
    End Function[/vba]
    In the userform
    [vba]Option Explicit

    Private Sub cmdOKBttn_Click()
    strPWord = txtPWord
    strUser = txtUser
    strDomain = txtDomain
    strProject = txtProject
    Unload Me
    End Sub

    Private Sub cmdCancelBttn_Click()
    bolBailOut = True
    Unload Me
    End Sub[/vba]
    Now that probably didn't help, did it? I figure you probably need some way of gracefully exiting the function if the user cancels. If this is the case, we'd need to see a bit more of what's going on to see what's needed. Make sense?

    I do have one generic suggestion though , try calling the userform BEFORE getting into the function. Then call the function from the userform, with the args being passed as the values from the various text or other controls. If the user cancels or supplys bad vals, don't call the function. Does that help at all?

    Hope to help,

    Mark

  5. #5
    VBAX Regular
    Joined
    Nov 2008
    Posts
    41
    Location
    Hi GTO,
    Thanks for the help. I'll try working on this again now and get back to you when it doesn't work.
    Wannes

  6. #6
    VBAX Regular
    Joined
    Nov 2008
    Posts
    41
    Location
    Hi,

    I tried your last suggestion, and with a dummy sub that displayed the passed parameter, it worked.

    However, with my more advanced function, the debugger gives an error on the first, displaying he doesn't find a library.

    What should I do?

    I'll try this:
    Call a freshly made function from my main sub.
    within the freshly made function interact with the form
    return the values to the main sub

    I'll let you know whether it works

    EDIT: I found why he didn't find the library: I was using it on a computer that had no access to the API
    Last edited by Marcke; 12-23-2008 at 10:43 AM.

  7. #7
    VBAX Regular
    Joined
    Nov 2008
    Posts
    41
    Location
    Ok, it worked, thanks for the help!

  8. #8
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Well shucks(!), I didn't think that'd be near enough to be of any assistance. Glad you "got 'er running"

  9. #9
    VBAX Regular
    Joined
    Nov 2008
    Posts
    41
    Location
    Euihm, well, I used your generic approach, also learned that i could use byval somewhere else, and the unload me also helped, as i did not know this command yet.

Posting Permissions

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