Return to Website

MS Access

Computers at Large brings MS Access Forum for you to ask questions, answer questions or look up solutions

MS Access
Start a New Topic 
Login & Report Generation

Hello Terry,

I have got a username and password set on each of my forms in my database. I have got the following code:

Private Sub Form_Load()

Dim strPassword As String

strUsername = InputBox("Please enter your database username:", "Stock And Sale Administrators", "", 200, 200)

If Not UCase(strUsername) = "houstong" Then DoCmd.Close

strPassword = InputBox("Please enter your database password:", "Stock And Sale Administrators", "", 200, 200)

If Not UCase(strPassword) = "password22" Then DoCmd.Close

End Sub

-I was wondering if you could tell me how I could add another username and another password to this code.

Also, is there any VBA code to *automatically* generate a report in a pre-defined layout design from clicking a command button on a form? Ideally, the report would contain only the record currently being displayed on the form, as well as all records that are linked to it. The reason I am asking you this, is because I want to know how to create an invoice automatically just by clicking a command button.

Thanks for your help!

Re: Login & Report Generation

I would do this: create a table with Usernames and Passwords (it does not have to be really long). Then I would have a login in form. It could be as simple as an Unbound Form. You would just have two text boxes for the user to enter the username and password. A command button, that opens the UserName Table and looks through it to find the Username and Password (if it is there it would open a new form, if not it would open a form that tells the user it is a bad password.) This input form does not need scroll bars, navigation buttons, just a plan form. Doing it the way you have your code, is that the usernames and passwords have to be embedded in the actual code.

If you refer to the username that was entered it would look like: Forms!frmLogin!txtUserName....if you keep that login form open, you can refer to the Username over and over again for your reports, querys, etc.

Report - Create your report, base it on a query, in the query for the criteria have it as Forms!frmLogin!txtUserName (for that user, or change it for another field.) Then the report will only use that Username or whatever else you want to pick.

Put a command button on the form with the Docmd.OpenReport "MyReportName", Preview line of code for the on_click event....and then you are set to go!