Visual Basic Help me...Brain hurts....

Watch
This discussion is closed.
Mizar
Badges: 0
#1
Report Thread starter 16 years ago
#1
Linking to a Work sheet from a User form
I have a user form with a command button on it and a to text boxes for a User name and a password.

I want to be able to get the userform to go to a sheet in the workbook and check to see if the data entered in the texboxes matches an entry in the cells, and if it does to open a new user form with the .show command


Also



I want to stop a user from Closing a VBA User Form in Excel. Is there a way of continuingly opening the window until the user hits a certain button. If they close it down and the button is not clicked then it reopens
. Ive got a rough idea of how to do it but implementing the coding proves illusive.

Can some one help me?
0
Mizar
Badges: 0
#2
Report Thread starter 16 years ago
#2
Oh yea im using VB version 6 too.
0
Rich
Badges: 2
Rep:
?
#3
Report 16 years ago
#3
(Original post by Mizar)
Linking to a Work sheet from a User form
I have a user form with a command button on it and a to text boxes for a User name and a password.

I want to be able to get the userform to go to a sheet in the workbook and check to see if the data entered in the texboxes matches an entry in the cells, and if it does to open a new user form with the .show command
I assume you're using VBA within Excel and not actually Visual Basic full version.

To reference for example cell C2 in a sheet called 'Sheet1' in a workbook called 'Book1.xls', you would write:

Code:
Workbooks("Book1.xls").Sheets("Sheet1").Cells(2, 3).value
So to compare this value with some text in a textbox, something like the following should suffice:

Code:
If Workbooks("Book1.xls").Sheets("Sheet1").Cells(2, 3).value = txtTextBox.Text Then
        ' do whatever
End If
However you may want to convert the text in the textbox to a specific type if the cell is of that type, for example, using IsNumeric(txtTextBox.Text) and CInt(txtTextBox.Text) to check for validity and to perform the conversion respectively in the case of numeric values. There are similar functions such as IsDate(..) and CDate(..) available also... see the help file for more information.

Note that you can also do things like ThisWorkbook.ActiveSheet.Cells(2 ,3).value or ThisWorkbook.Sheets("Sheet2").Ce lls(2,3).value if you have only one workbook or want to reference the active sheet etc. Loads more information is available in the help files.

(Original post by Mizar)
I want to stop a user from Closing a VBA User Form in Excel. Is there a way of continuingly opening the window until the user hits a certain button. If they close it down and the button is not clicked then it reopens
. Ive got a rough idea of how to do it but implementing the coding proves illusive.

Can some one help me?
Hmm... I'm currently in Linux so this is all from memory. I think you can remove the 'cross' by fiddling with the form properties... and there's also a parameter you can set in an event handler on Form_Unload to cancel the close operation if I remember correctly. I think Cancel = 1. If you really want to keep it open you will need to do some complicated API calls to remove its entry from the task manager etc.

Google Groups (http://groups.google.com) is your friend!
0
DazYa4
Badges:
#4
Report 16 years ago
#4
i went to london yesterday and went to imperial college yesterday
its not all that good and there are so many developments going on... its a mess at the moment
mostly saw chinese people, and people with glasses.

however london is awesome and i love it
0
Nylex
Badges: 10
Rep:
?
#5
Report 16 years ago
#5
(Original post by DazYa4)
mostly saw chinese people, and people with glasses.
What's wrong with that?
0
DazYa4
Badges:
#6
Report 16 years ago
#6
(Original post by Nylex)
What's wrong with that?
nothing at all but i prefer to see the odd attractive female on campus
....
only saw one but am not even sure she was from imperial
0
Mizar
Badges: 0
#7
Report Thread starter 16 years ago
#7
Thanks alot il give that a try and implement it.
0
X
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Should the rest of the UK follow the Scottish Results changes announced?

Yes they should (91)
52.91%
No they should not (61)
35.47%
Abstain (20)
11.63%

Watched Threads

View All