Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello first of all I explain what I have in my hands.
Two masks, in mask A, there is the "user" field and other fields (what interests me is "user"). While in Mask B it would be the login, with username and password.

When I enter a User in Mask A, I automatically open the Login Form with which I identify who accesses. In this way I would like to take (when the credentials are entered correctly) username of the person who logs in and put it with "User" in Mask A.

I created a global variable "Username1".
This is the code I did test and the message I used to understand works. But I can not use it by putting it in the box I would like.

VB
Private Sub Employee_AfterUpdate()

DoCmd.OpenForm FormName:="login", WindowMode:=acDialog
MsgBox username1

End Sub


This is the global variable.
VB
Option Compare Database
Option Explicit

Public username1 As String


I hope I explained myself. Thank you




Code of Login
VB
Private Sub Command0_Click()
DoCmd.CloseDatabase
End Sub

Private Sub Command1_Click()

    If IsNull(Me.tb_ID) Or IsNull(Me.tb_pwd) Then
      MsgBox "You must enter password or login ID.", vbOKOnly + vbInformation, "Required Data"
      Me.tb_ID.SetFocus
        Exit Sub
    End If
    
    If Me.tb_pwd.Value = DLookup("[psw]", "Utenti", "[User]='" & Me.tb_ID.Value & "'") Then
      username1 = Me.tb_ID.Value
      DoCmd.Close acForm, "login", acSaveNo
      DoCmd.OpenForm "Work Hours List"
    Else
      MsgBox "Password or login ID incorrect. Please Try Again", vbOKOnly + vbExclamation, "Invalid Entry!"
      Me.tb_pwd.SetFocus
    End If
    
End Sub


Code of what i tried with the field Employee
VB
Private Sub Employee_AfterUpdate()

DoCmd.OpenForm FormName:="login", WindowMode:=acDialog
MsgBox username1

End Sub


Private Sub Form_Close()

DoCmd.OpenForm "login"

End Sub


What I have tried:

VB
Private Sub Employee_AfterUpdate()

DoCmd.OpenForm FormName:="login", WindowMode:=acDialog
MsgBox username1

End Sub

Private Sub Form_Close()

DoCmd.OpenForm "login"

End Sub




VB
Private Sub EmployeeText_AfterUpdate()

DoCmd.OpenForm FormName:="login", WindowMode:=acDialog
MsgBox username1
Me.EmployeeText.Value = username1

End Sub
Posted
Updated 3-Jan-19 2:36am
v4

1 solution

I have no idea what your Mask A and Mask B could be, and the explanation is very confusing.

The title, however, is clear, and the answer is simple. In the form, where you have that field bound to a control (textbox), assign the global to the Value property in, say, the OnOpen event of the form:
VB
Me!YourTextbox.Value = username1
 
Share this answer
 
v2
Comments
Atipos 3-Jan-19 6:14am    
The problem is that the field hasn't a value property. It gives me this error: "Object doesn't support this property or method"

The field is "employee", with it i can select an employee from a list of them, when i select the name of the employee it will open the login form, with this i will put the username and password.
What i like to do is that the username
Gustav Brock 3-Jan-19 7:57am    
I can see on SO, that you don't have a field but a label. For a label, assign the global to the Caption property of the label.
Atipos 3-Jan-19 8:32am    
I really appreciate your availability and I thank you. Using the caption property what I'd like to do, it works great. But unfortunately changes the title of the column. Thanks to you I understand that I have to operate on that precise field.

Now I wrote:

Me.Employee_Label.Caption = username1



Having done this, as written a little above, change the title of the column.

If you now put:

Me.EmployeeText.Value = username1

I'm back to the run-time error 2113, the value you enteres is not valid for this field.



https://imgur.com/JuMjLNn
- I upload a little image of what i like to change with the global
Gustav Brock 3-Jan-19 9:09am    
It looks like your field is a combobox bound to the field. Then you (typically) must supply the ID of the username, but - from your code - that already seems to be the case and what is stored in username1.

Try a little debugging and check that you manually can enter the value in the table.
Atipos 4-Jan-19 4:33am    
If row source of combobox is

SELECT [Employees Extended].ID, [Employees Extended].[Employee Name] FROM [Employees Extended];

should i work on this? I mean, with Me.X.Value=username1.
I don't konw if i can reach an object that is on another table of the database.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900