Thank god you use option explicit.
It's unclear to me what you actually want to do, but here's why your code errors out:
In the macro btnProcess_Click, change the following:
This should be:
Next up - you've got the following line in your code:
but you don't have the label errHandler anywhere. Remove this line.
Next up, in the following line you define the variable 'Code' as Clng, but that will error if the user inputs a password that isn't numerical.
Solution would be to either remove the CLng or change your textbox to only allow numbers.
(I think removing CLng would be easier for you )
Next up - you define a VBA function (MsgBox) as a variable.
While that's not technically impossible, it's very bad practice. Change the name of your variable here into something like MsgBx
But better still, remove the variable setting above entirely and remove the "=" from the two lines below:
Then, this macro will run without errors.
However, it really seems like you are not very sure of what you're doing and I have my sincere doubts that this code will actually (ever) do what you aim to do, so perhaps it's better to start from scratch and tell us exactly what it is you're looking to accomplish with this sheet.
As for your other questions:
2. How should I do the coding if I want the user to select the username, then the department will be auto show up.
Honestly, I can explain this to you, but it wouldn't help much as long as your code is still such a mess...
3. Is it possible to have a progress bar when password is correct?
Yes. But progress bar for what? There's no additional code that runs, at least nothing that I see that would require a progress bar, so it doesn't make sense.
Bookmarks