Hi,

I have a login screen where user enters their name and password. The username and password are stored in access. Then when the user opens forms i need their username to appear in the form. Can somebody give me code for that please.

Thanks
Krs

Hi Krs13,
See my Attached help. I think this is exactly what you want.
Hope this helps
Thanks

nice example. I have nothing to say after it.

Hi Krs13,
See my Attached help. I think this is exactly what you want.
Hope this helps
Thanks

Hi,

I couldnot open the attachment what you have given.. Can you please help.

Krs

1st download & unzip it. and then open it.

1st download & unzip it. and then open it.

Hi,

I did the same thing what you have told but when i unzip and open it opens microsoft picture manager and shows a icon, thats it.

Can you send the unzip file or zip file again.


Thanks
Krs

OK then I am sending it again. Try it once again. Here it does not allow me to attach frm, vbp, and mdl files. If this doesn't work then we will need to fine other alternative so that I can send.
Thanks

OK then I am sending it again. Try it once again. Here it does not allow me to attach frm, vbp, and mdl files. If this doesn't work then we will need to fine other alternative so that I can send.
Thanks

Sorry its not opening it for me..Is it not possible to write code in text file and send it.

Krs

it opens microsoft picture manager and shows a icon,

I have send private message for you any way try the following once.
1. Locate Logon.vbp file and
2. Instead of double click, right-click and select Open with
3. Select Visual Basic from the Select Options dialog box

I hope this will solve your problem
Thanks

Hi,

I have a login screen where user enters their name and password. The username and password are stored in access. Then when the user opens forms i need their username to appear in the form. Can somebody give me code for that please.

Thanks
Krs

I suggest you to use a MDI Form with a Status Bar, where you can make appear the Username, User number, Date, Time etc... inside the each panel.

Make use of a public sub as in (Depending on your database used, in this case MS Access -

Public Sub GetDbAll(conn As ADODB.Connection, strUsername As String)
Set conn = New ADODB.Connection

conn.Open "provider = microsoft.jet.oledb.4.0;persist security info=false;data source =" & strpath & ".mdb"  ' C:\MyDatabase.mdb" 'MyDatabase being your database name

conn.CursorLocation = adUseClient
conn.Open

Dim rsDb As ADODB.Recordset
Set rsDb = New ADODB.Recordset

rsDb.Open "SELECT * FROM MyLoginTable", conn, adOpenStatic, adLockOptimistic

strUserName = rsDb!MyUsername 'The field for your username
End Sub

'Under a form load event - 

Dim conn As ADODB.Connection
Set conn = New ADODB.Connection

GetDbAll conn, Text1

'This will set the text in Text1 to the username.

Make use of a public sub as in (Depending on your database used, in this case MS Access -

Public Sub GetDbAll(conn As ADODB.Connection, strUsername As String)
Set conn = New ADODB.Connection

conn.Open "provider = microsoft.jet.oledb.4.0;persist security info=false;data source =" & strpath & ".mdb"  ' C:\MyDatabase.mdb" 'MyDatabase being your database name

conn.CursorLocation = adUseClient
conn.Open

Dim rsDb As ADODB.Recordset
Set rsDb = New ADODB.Recordset

rsDb.Open "SELECT * FROM MyLoginTable", conn, adOpenStatic, adLockOptimistic

strUserName = rsDb!MyUsername 'The field for your username
End Sub

'Under a form load event - 

Dim conn As ADODB.Connection
Set conn = New ADODB.Connection

GetDbAll conn, Text1

'This will set the text in Text1 to the username.

AndreRet,

What you have posted is to get username from mdb(i.e) login page. But i want the username in other forms after logging in the main form.

Krs13,
I have sent you private message giving my email address. So mail me and in your reply I will send my previous attached help. or Just give me your email address.
Thanks

Since that your connecting to your database, if the log in is successful, I suggest to store the inputted username in a global variable,..declare the global variable in a BAS module..

Public curUsername as String

so that you can access anytime whose the user that is currently logged in...
then when the user logs out, clear the global variable's content like this:

curUsername = ""

Krs13, If you look at my code, the username can be called whenever you need it and in whichever form you need it -

'Under a form load event -

Dim conn As ADODB.Connection
Set conn = New ADODB.Connection

GetDbAll conn, Text1

'This will set the text in Text1 to the username.

The Text1 part is the holding string for the username, which you can write into a textbox (Text1) or call it to any other function you need it for.

Krs13,
I have sent you private message giving my email address. So mail me and in your reply I will send my previous attached help. or Just give me your email address.
Thanks

Kinwang,

Thanks i opened your attachement in another system and could see the code. Thanks for your help.

Krs

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.