Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding or Making a Form Invisible? 2

Status
Not open for further replies.

435

Technical User
Jul 22, 2003
24
US
I want a record to be created as of what user modifies the CUSTOMER form.
I have 2 forms

LOGIN
CUSTOMER

On the CUSTOMER form I have a button that when I
ClickOnSaveButton it copys the UserName from the LOGIN form.

But In order for ClickOnSAveButton to copy the UserName from
the LOGIN form this has to be open otherwise an error message comes up saying that it couldn't find the LOGIN form.

My question is how do i hide or make invisible
the LOGIN form? I think that if the form is hidden, since it
is still there it should allow for the code to copy from the LOGIN form. Or What Code should I Use

The code that I used on the customer form is..
(Me.Text72.Value = Forms!Login!txtname.Value)
 
One of the options of the DoCmd.OpenForm method is to open the form hidden. The other thing you can do is to store the login name in a public variable. Then you don't have to worry about keeping the Login form open. I'm assuming you have your own login form. If you let Access login your users, the variable CurrentUser contains the name of the user who is logged in.
 

The LOGIN form has to be visible in order to login, i think.
I like the other ide as to store the LoginName in a public variable.

I have my own form but Im not sure on how to store that public variable, can you give me an Example.

Thanks for the reply!
 
Open a new module and insert the following code

Public gstrCurrentUser as String

Name this module something like: modPublicDeclarations

In the OnClose event of the form, set gstrCurrentUser equal to the field that contains the login name.

gstrCurrentUser = txtLoginName
 
forms!login.visible = false

you can then set it to true whenever you want
 
Ok, I created a module named :modPublicDeclarations
with the code:

Public gstrCurrentUser as String

Then did the following

OnClose event of the form, gstrCurrentUser equal to the field that contains the login name.

gstrCurrentUser = txtname

Then I went to the CUSTOMER form and modified :

from-->Me.Text72.Value = Forms!Login!txtname.Value
to---->Me.Text72.Value = CurrentUser.Value

But now I get a compile error and CurrentUser is highlighted! Whats wrong with that sintax? Or what other code shoul I User.??????????
 
CurrentUser is a reserved word in Access. It refers to the User who is currently logged on (default: Admin). It's not CurrentUser.Value. But since you are using your own login, then you need to use the public variable we setup. Like this:

Me.Text72.Value = gstrCurrentUser
 
Thank you very much, I really apreciate your patience.
Problem Solved.

It was a great treasure finding the tek-tips forum. In the last couple of weeks I've learned a lot.

Latez, See you guyz soon.
 
Hi Fancy,

How would I capture the currentuser to a table so I can have a logged of who login and when?

Thanks
 
I don't know how your screen is laid out, but assume that once the user logins in he/she presses an OK button. In the OnClick event of the OK button, add the following code. Note, the code assumes the name of your table is "tblLoginHistory" and it assumes that gstrCurrentUser has already been populated.

Dim rst As ADODB.Recordset

Set rst = New ADODB.Recordset

rst.Open "tblLoginHistory", CurrentProject.Connection, adOpenDynamic, adLockPessimistic

rst.AddNew
rst!strLoginName = gstrCurrentUser
rst!dteLogin = Now()
rst.Update

rst.Close

Set rst = Nothing
 
Fancy,

Thank you so much for the fast reply. I will give this a try.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top