View Full Version : Solved: How to pass login parameters from a form to a function
Marcke
12-22-2008, 08:59 AM
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:
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
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.
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
Marcke
12-23-2008, 01:48 AM
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.
Marcke,
Here's code based upon your input:
In a standard module:
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
In the userform
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
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
Marcke
12-23-2008, 09:28 AM
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
Marcke
12-23-2008, 10:31 AM
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
Marcke
12-23-2008, 12:27 PM
Ok, it worked, thanks for the help!
Well shucks(!), I didn't think that'd be near enough to be of any assistance. Glad you "got 'er running":thumb
Marcke
12-24-2008, 01:56 AM
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.