Automatically Add New Users and Open to their page (1 Viewer)

NearImpossible

Registered User.
Local time
Today, 12:00
Joined
Jul 12, 2019
Messages
225
I am working on a database that will either automatically add a network user to the UserLogins table, and then open the UserInformation form to that record so they can add in their details, or if they already exist in the UserLogins table, then they will be redirected to the appropriate form based on their permission level.

I have a function to get the User Name for the individual launching the database and then pass that to the UserLogins table, which is working.

Currently I am stuck at opening the UserInformation form to the newly added record as it adds the name to the table correctly, but then I am presented with an "Enter Parameter Value" for the NetworkUser, vs it being passed through.

When I type in the NetworkUser, it opens the form and displays the correct record.

Here is the code I have

Code:
Dim Rs As Recordset
'Check to see if the Network User is a new user and opens the applicable forms
    UsrLogin = DLookup("UserLogin", "dbo_db_UserLogins")

    If IsNull(UsrLogin) = True Then
        'Adds first Network User to UserLogins table and opens User Information form
            Set Rs = CurrentDb.OpenRecordset("dbo_db_UserLogins", dbOpenDynaset, dbSeeChanges)
                Rs.AddNew
                Rs!UserLogin = NetworkUser
            Rs.Update
                        
           [COLOR="Red"][B] DoCmd.OpenForm "UserInformation", , , "[UserLogin]= " & NetworkUser[/B][/COLOR]
    Else
        If UsrLogin = NetworkUser Then
            'Opens applicable form
        
        Else
            'Adds new Network User to UserLogins table and opens User Information form
                Set Rs = CurrentDb.OpenRecordset("dbo_db_UserLogins", dbOpenDynaset, dbSeeChanges)
                    Rs.AddNew
                    Rs!UserLogin = NetworkUser
                Rs.Update
                
            [COLOR="red"][B] DoCmd.OpenForm "UserInformation", , , "[UserLogin]= " & NetworkUser[/B][/COLOR]
             
        End If
   End If

Any help is apprechiated

Thank you
Kevin
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:00
Joined
Oct 29, 2018
Messages
21,467
Hi Kevin. If you're being asked to enter a parameter, it usually means you may have misspelled the name of a field in your code.
 

GinaWhipp

AWF VIP
Local time
Today, 13:00
Joined
Jun 21, 2011
Messages
5,899
Hmm, I see *UsrLogin* and *UserLogin* used. Are you sure both spellings are correct and you are referencing them correctly based on their source object?
 

NearImpossible

Registered User.
Local time
Today, 12:00
Joined
Jul 12, 2019
Messages
225
Hi Kevin. If you're being asked to enter a parameter, it usually means you may have misspelled the name of a field in your code.

theDBguy, I get what your saying, but "NetworkUser" is the name of a Function to get the currently logged in user on the PC

Code:
Option Compare Database

Declare Function wu_GetUserName Lib "advapi32" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long

Function NetworkUser() As String

Dim lngStringLength As Long
Dim sString As String * 255

lngStringLength = Len(sString)
sString = String$(lngStringLength, 0)

If wu_GetUserName(sString, lngStringLength) Then
    NetworkUser = Left$(sString, InStr(sString, Chr(0)) - 1)
Else
    NetworkUser = "Unknown"
End If

End Function

and "[UserLogin]" is the field on the UserInformation form, I'm trying to pass NetworkUser into my OpenForm Where statement.

Code:
DoCmd.OpenForm "UserInformation", , , "[UserLogin]= " & NetworkUser

I am guessing NetworkUser isn't being passed correctly as I am being prompted to enter the parameter. When I type in the name, it opens the form to the correct user page.



Hmm, I see *UsrLogin* and *UserLogin* used. Are you sure both spellings are correct and you are referencing them correctly based on their source object?

GinaWhipp, UsrLogin is the result of the DLookup in the dbo_db_UserLogins table where its checking the "UserLogin" column, which I then use to match against the NetworkUser.

Code:
UsrLogin = DLookup("UserLogin", "dbo_db_UserLogins")

UserLogin is also the field name on the UserInformation form
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 10:00
Joined
Oct 29, 2018
Messages
21,467
Hi. If NetworkUser() returns a string, then you should probably delimit it in your code. However, doing so doesn't mean you'll get rid of the prompt. We'll need to see how everything works together to be able to tell you where the prompt is coming from. However, this is what I meant with the above:
Code:
DoCmd.OpenForm "UserInformation", , , "[UserLogin]= '" & NetworkUser() & "'"
 

NearImpossible

Registered User.
Local time
Today, 12:00
Joined
Jul 12, 2019
Messages
225
Ha, that's exactly what it was, I can't believe I missed that, I guess thats what happens when you start coding after a long day and little sleep.

Code:
DoCmd.OpenForm "UserInformation", , , "[UserLogin]= '" & NetworkUser & "'"

It is a string, even says so in the code :banghead:

Code:
Function NetworkUser() As String

thanks again to all !!
Kevin
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:00
Joined
Oct 29, 2018
Messages
21,467
Ha, that's exactly what it was, I can't believe I missed that, I guess thats what happens when you start coding after a long day and little sleep.

Code:
DoCmd.OpenForm "UserInformation", , , "[UserLogin]= '" & NetworkUser & "'"
It is a string, even says so in the code :banghead:

Code:
Function NetworkUser() As String
thanks again to all !!
Kevin
Hi Kevin. Congratulations! Glad to hear you got it to work. Good luck with your project.
 

Cronk

Registered User.
Local time
Tomorrow, 03:00
Joined
Jul 4, 2013
Messages
2,772
There is a logic problem with your code in that
Code:
UsrLogin = DLookup("UserLogin", "dbo_db_UserLogins")
will return Null for the first user but after the first user has been entered, it will return for the second user, the first user's login.


You need to have
Code:
UsrLogin = DLookup("UserLogin", "dbo_db_UserLogins", "UserLogin='" & NetworkUser & "'")
to test the second user's login.
 

NearImpossible

Registered User.
Local time
Today, 12:00
Joined
Jul 12, 2019
Messages
225
There is a logic problem with your code in that
Code:
UsrLogin = DLookup("UserLogin", "dbo_db_UserLogins")
will return Null for the first user but after the first user has been entered, it will return for the second user, the first user's login.


You need to have
Code:
UsrLogin = DLookup("UserLogin", "dbo_db_UserLogins", "UserLogin='" & NetworkUser & "'")
to test the second user's login.

Actually I discovered that as well when I started testing with additional users, but thanks for pointing it out !!

I ended up changing a few other things as well, but it is now running as intended.

Thanks again to all !!
 

Users who are viewing this thread

Top Bottom