Turn on thread page Beta
    • Thread Starter
    Offline

    0
    ReputationRep:
    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?
    • Thread Starter
    Offline

    0
    ReputationRep:
    Oh yea im using VB version 6 too.
    Offline

    2
    ReputationRep:
    (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!

    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
    Offline

    10
    ReputationRep:
    (Original post by DazYa4)
    mostly saw chinese people, and people with glasses.
    What's wrong with that?

    (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
    • Thread Starter
    Offline

    0
    ReputationRep:
    Thanks alot il give that a try and implement it.
 
 
 
Poll
Do you think parents should charge rent?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.