Urgent help needed! Logging in and getting a form to open at a specific record

e_Clark

New member
Local time
Today, 22:51
Joined
Jan 13, 2010
Messages
9
Hi Guys,

I'm a newbie here, so I really hope someone can help me! I'm also very very new to programming, so I just have a grasp of the basics....

What I am trying to do is create a log in screen for my database. When the user logs in, I want them to go to the user form, but not just that, I would like them to be taken straight to their record. So they log in, and the user form opens up automatically at their record.

Can anyone help with how to do this, I've used the:

docmd.openform"Selections", , , XXXX

with the XXX being the bit I do not know how to enter that tells the form on what record to open.

Can anyone help with how to do this? I need it really urgently!

Thanks.
 
The 4th argument of the OpenForm function is the WhereCondition argument. It is a string value that applies a filter to the RecordSource of the form you are opening. It does *not* contain the word "WHERE"! Let's say you want a certain Employee record and you have a LongInteger field called EmployeeID. Your WhereCondition argument might look something like:
"[EmployeeID] = " & Me.EmployeeIDControlOnTheFirstForm
 
The 4th argument of the OpenForm function is the WhereCondition argument. It is a string value that applies a filter to the RecordSource of the form you are opening. It does *not* contain the word "WHERE"! Let's say you want a certain Employee record and you have a LongInteger field called EmployeeID. Your WhereCondition argument might look something like:
"[EmployeeID] = " & Me.EmployeeIDControlOnTheFirstForm

Ok, so to clarify, I have a form called Employee, where their details are heled, including an employeeID. I then have a form called Selections where their choices about something are held.

What I am wanting is to log in, and for their record in the Selections table to be shown, and if there isn't one already, for it to show a blank new record.

How would I do this, as I realise that this is slightly different to just finding their record in the Employee form.

Thanks.
 
In that case my preference is to pass the EmployeeID in the OpenArgs argument of the OpenForm function. Then examine it in the OnLoad event and try and locate and go to the record. If it does not exist just move the RecordPointer to a new record or put the form in DataEntry mode.
 
In that case my preference is to pass the EmployeeID in the OpenArgs argument of the OpenForm function. Then examine it in the OnLoad event and try and locate and go to the record. If it does not exist just move the RecordPointer to a new record or put the form in DataEntry mode.

I'm really sorry, I really an a real novice at this and am not really following you (though I'm sure its v useful and I'm grateful for that!).

Is there any chance that you could write out the code expression for me, I'm just getting in a massive muddle about what goes where and am ready to through my pc out the window!
 
I cheated!

I added User Login to the Employees File and then identified the user:
Code:
Function GetWinUserName()
    GetWinUserName = VBA.Environ("UserName")
End Function

Then looked at the Employee record:
Code:
Function GetUser()
Dim db As DAO.Database
Dim rs As DAO.Recordset
    With CodeContextObject
        Set db = CurrentDb
        Set rs = db.OpenRecordset("SELECT EmployeesLookup.Employee FROM EmployeesLookup WHERE EmployeesLookup.[Employee Login] = '" & GetWinUserName & "'")
        Do
            
        Then do whatever
 
        rs.MoveNext
        Loop Until rs.EOF
    
        rs.Close
        Set rs = Nothing
        Set db = Nothing
    End With
End Function

Simon
 

Users who are viewing this thread

Back
Top Bottom