Forum Home
Press F1
 
Thread ID: 67990 2006-04-13 00:48:00 VB / MS Access pico (4752) Press F1
Post ID Timestamp Content User
446030 2006-04-13 00:48:00 Hi,

I am trying to write some VB for an Access DB I am creating . I have not learnt VB and am trying to teach myself (by making mistakes and reading the help file) .

I am currently setting up a login to the DB where you select which user you are and enter a password . These are stored in a table in the database . I have managed to write some code that looks up the username and compares it to the password and then will either tell you your password is incorrect or will take you to the main screen of the database .

I just want to know how to store the username for use in other parts of the DB . From what I understand any variable will be dropped when the code stops running and I'm not sure if the variable will be available to other bits of code (excuse me if I am not using correct terminology) . I did thinkk of getting it to enter the username in a 1 x 1 table that gets modified whenever someone logs in but I thought that was quite ugly .

Any ideas (even a VERY simple free web based tutorial to teach me to code from fundamentals would be good) .

:)
pico (4752)
446031 2006-04-13 01:31:00 In VB help, search for "public variables". If you declare a variable as public, it becomes available to all proceedures in your project. wuppo (41)
446032 2006-04-13 07:28:00 Hi
I explained a method of doing this in this thread (www.mrexcel.com) - sorry its from another forum but it walks you through how to do this. Be aware it is a relatively weak form of security.
Andrew
andrew93 (249)
446033 2006-04-13 09:58:00 Thanks guys they were both useful .

Wuppo
I had read about declaring variables as public but I don't know if that works across multiple forms? Also how do I access that variable? I . e . can I just type the variable name in a text box?

Andrew
From what I can understand you pass the value of the user to a text box on the next form . Is this the only way to do it? Because if you to then go to another form you'd have to pass the value to that form too wouldn't you? Is there no way to set a variable that is available the whole time you have the DB open?

Thanks
pico (4752)
446034 2006-04-13 12:23:00 Yes there is. You pass the value to a form that is hidden from the users but can be access from VBA. Or the other forms are 'pop up' forms that stay on top of the switchboard (refer to the pop up and modal properties of the forms) and you pass the ID on to the switchboard.
A
andrew93 (249)
446035 2006-04-17 23:23:00 Thanks Andrew,

I thought about the Switchboard idea and I thought well if I'm going to reference a control on a form I may as well leave the login form open. But I need to make sure that you can't change it once you are "logged in." The best I have been able to do so far is make it minimise the login form. But you can easily maximise it again. Do you know of a way to make it so it can't be maximised and/or change the properties of the controls on the form so they can't be modified?

Cheers
pico (4752)
446036 2006-04-18 00:41:00 I also have another query,

I am trying to set up a Form that lets you view the various projects. I am displaying the projects in a list box with five headings. I have created some check boxes above that field which I want to filter the projects displayed in the list box below. I have managed to write the SQL statement in the row source for the list box but when it runs the SQL statement to populate the list box it displays message boxes requesting the values it should be obtaining from the check boxes. So it appears that the values in the check boxes are not available to it. Any suggestions? I have set the check boxes so that when they are updated the list box is requeried but it again requests the values, so does that mean I am referencing it incorrectly?
pico (4752)
446037 2006-04-18 02:28:00 Don't worry about this, I have come back from lunch and it seems to work now (I think I fixed an error I made). However the issue with making the login screen non-editable once logged in I''m still stuck on.


I also have another query,

I am trying to set up a Form that lets you view the various projects. I am displaying the projects in a list box with five headings. I have created some check boxes above that field which I want to filter the projects displayed in the list box below. I have managed to write the SQL statement in the row source for the list box but when it runs the SQL statement to populate the list box it displays message boxes requesting the values it should be obtaining from the check boxes. So it appears that the values in the check boxes are not available to it. Any suggestions? I have set the check boxes so that when they are updated the list box is requeried but it again requests the values, so does that mean I am referencing it incorrectly?
pico (4752)
446038 2006-04-18 08:55:00 Thanks Andrew ,

I thought about the Switchboard idea and I thought well if I'm going to reference a control on a form I may as well leave the login form open. But I need to make sure that you can't change it once you are "logged in." The best I have been able to do so far is make it minimise the login form. But you can easily maximise it again. Do you know of a way to make it so it can't be maximised and/or change the properties of the controls on the form so they can't be modified?

Cheers
Hi pico

Once the user has successfully logged in, you could use VBA to set set the 'enabled' property of the login id text box to 'No' and set the 'visible' property of the login form to 'No'. That might do the trick by disabling the text box and making the form invisible to the users. If you need help with the code, can you post the code you currently have on your login button?

Andrew
andrew93 (249)
446039 2006-04-18 09:17:00 Thanks Andrew,

I had seen those properties but I don't know how to change them using VB code. I don't have the code I am using here at home but I will post it from work when I get there tomorrow. If you know the commands to change the attributes of controls in VB that would be great. Do you just go something like:

controlname = "value"

Thanks
Ross
pico (4752)
1 2