Match/No Match

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi,

I am creating a database for many users. I run a function
that picks up their username (from a dll file).

I have also created a table holding details on some of the
users, this table also holds their status for access
rights.

On open, the username is put into a public variable within
the db. Is there any code I can use to say if the username
is in the [userId] field in the [user] table? I will run
an If statement depending if true or false.

Many thanks,

Mike
 
I've done something that seems to work, but I botched it
together!! - could you tell me if is rubbish or how it
could be tidied up please. Here is what I botched:

Option Compare Database
Option Explicit

Public KnownUser As Boolean
Public OKToAction As Boolean
Public UserFullname As String
Public UserForename As String
Public UserStatus As String
Public CurrentUser As String
Public AdministratorName As String
Public AdministratorEmail As String

Public Sub LoadUser()
CurrentUser = CurrentUserID

Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Users", dbOpenDynaset)
rst.FindFirst "UserID = '" & CurrentUser & "'"
If rst.NoMatch Then
KnownUser = False
Else
KnownUser = True

End If
rst.Close

If KnownUser = False Then
UserStatus = "Unknown User"
UserForename = "Unknown User"
UserFullname = "Unknown User"
Else
UserStatus = DLookup("Status", "Users", "[UserID]
= '" & CurrentUser & "'") 'Searches for info in Users table
UserForename = DLookup
("Forename", "Users", "[UserID] = '" & CurrentUser & "'")
UserFullname = DLookup
("Forename", "Users", "[UserID] = '" & CurrentUser & "'") _
& " " & DLookup
("Surname", "Users", "[UserID] = '" & CurrentUser & "'")
End If

AdministratorName = DLookup
("Forename", "Users", "[Main Administrator Flag] = 'Y'") _
& " " & DLookup
("Surname", "Users", "[Main Administrator Flag] = 'Y'")

Thanks loads for getting this far down!! If you know how
it can be tidied (or if it rubbish and unreliable), please
let us know!

Mike
 
Mike,

If you hold off on closing the recordset until the end, you can get
rid of all the DLOOKUP functions. Also, you can combine the two IF
statements into one.

Option Compare Database
Option Explicit

Public KnownUser As Boolean
Public OKToAction As Boolean
Public UserFullname As String
Public UserForename As String
Public UserStatus As String
Public CurrentUser As String
Public AdministratorName As String
Public AdministratorEmail As String

Public Sub LoadUser()
CurrentUser = CurrentUserID

Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Users", dbOpenDynaset)
rst.FindFirst "UserID = '" & CurrentUser & "'"
If rst.NoMatch Then
KnownUser = False
UserStatus = "Unknown User"
UserForename = "Unknown User"
UserFullname = "Unknown User"
Else
KnownUser = True
UserStatus = rst("Status") 'Searches for info in Users
table
UserForename = rst("Forename")
UserFullname = rst("Forename") & rst("Surname")
End If

rst.close
AdministratorName = DLookup ("Forename", "Users", "[Main
Administrator Flag] = 'Y'") _
& " " & DLookup("Surname", "Users",
"[Main Administrator Flag] = 'Y'")


--
HTH

Dale Fye


I've done something that seems to work, but I botched it
together!! - could you tell me if is rubbish or how it
could be tidied up please. Here is what I botched:

Option Compare Database
Option Explicit

Public KnownUser As Boolean
Public OKToAction As Boolean
Public UserFullname As String
Public UserForename As String
Public UserStatus As String
Public CurrentUser As String
Public AdministratorName As String
Public AdministratorEmail As String

Public Sub LoadUser()
CurrentUser = CurrentUserID

Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Users", dbOpenDynaset)
rst.FindFirst "UserID = '" & CurrentUser & "'"
If rst.NoMatch Then
KnownUser = False
Else
KnownUser = True

End If
rst.Close

If KnownUser = False Then
UserStatus = "Unknown User"
UserForename = "Unknown User"
UserFullname = "Unknown User"
Else
UserStatus = DLookup("Status", "Users", "[UserID]
= '" & CurrentUser & "'") 'Searches for info in Users table
UserForename = DLookup
("Forename", "Users", "[UserID] = '" & CurrentUser & "'")
UserFullname = DLookup
("Forename", "Users", "[UserID] = '" & CurrentUser & "'") _
& " " & DLookup
("Surname", "Users", "[UserID] = '" & CurrentUser & "'")
End If

AdministratorName = DLookup
("Forename", "Users", "[Main Administrator Flag] = 'Y'") _
& " " & DLookup
("Surname", "Users", "[Main Administrator Flag] = 'Y'")

Thanks loads for getting this far down!! If you know how
it can be tidied (or if it rubbish and unreliable), please
let us know!

Mike
-----Original Message-----
Hi,

I am creating a database for many users. I run a function
that picks up their username (from a dll file).

I have also created a table holding details on some of the
users, this table also holds their status for access
rights.

On open, the username is put into a public variable within
the db. Is there any code I can use to say if the username
is in the [userId] field in the [user] table? I will run
an If statement depending if true or false.

Many thanks,

Mike
.
 
Glad I could be of assistance!

--
HTH

Dale Fye


Dale,

you are an angel.

M
-----Original Message-----
Mike,

If you hold off on closing the recordset until the end, you can get
rid of all the DLOOKUP functions. Also, you can combine the two IF
statements into one.

Option Compare Database
Option Explicit

Public KnownUser As Boolean
Public OKToAction As Boolean
Public UserFullname As String
Public UserForename As String
Public UserStatus As String
Public CurrentUser As String
Public AdministratorName As String
Public AdministratorEmail As String

Public Sub LoadUser()
CurrentUser = CurrentUserID

Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Users", dbOpenDynaset)
rst.FindFirst "UserID = '" & CurrentUser & "'"
If rst.NoMatch Then
KnownUser = False
UserStatus = "Unknown User"
UserForename = "Unknown User"
UserFullname = "Unknown User"
Else
KnownUser = True
UserStatus = rst("Status") 'Searches for info in Users
table
UserForename = rst("Forename")
UserFullname = rst("Forename") & rst ("Surname")
End If

rst.close
AdministratorName = DLookup ("Forename", "Users", "[Main
Administrator Flag] = 'Y'") _
& " " & DLookup ("Surname", "Users",
"[Main Administrator Flag] = 'Y'")


--
HTH

Dale Fye


I've done something that seems to work, but I botched it
together!! - could you tell me if is rubbish or how it
could be tidied up please. Here is what I botched:

Option Compare Database
Option Explicit

Public KnownUser As Boolean
Public OKToAction As Boolean
Public UserFullname As String
Public UserForename As String
Public UserStatus As String
Public CurrentUser As String
Public AdministratorName As String
Public AdministratorEmail As String

Public Sub LoadUser()
CurrentUser = CurrentUserID

Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Users", dbOpenDynaset)
rst.FindFirst "UserID = '" & CurrentUser & "'"
If rst.NoMatch Then
KnownUser = False
Else
KnownUser = True

End If
rst.Close

If KnownUser = False Then
UserStatus = "Unknown User"
UserForename = "Unknown User"
UserFullname = "Unknown User"
Else
UserStatus = DLookup("Status", "Users", "[UserID]
= '" & CurrentUser & "'") 'Searches for info in Users table
UserForename = DLookup
("Forename", "Users", "[UserID] = '" & CurrentUser & "'")
UserFullname = DLookup
("Forename", "Users", "[UserID] = '" & CurrentUser & "'") _
& " " & DLookup
("Surname", "Users", "[UserID] = '" & CurrentUser & "'")
End If

AdministratorName = DLookup
("Forename", "Users", "[Main Administrator Flag] = 'Y'") _
& " " & DLookup
("Surname", "Users", "[Main Administrator Flag] = 'Y'")

Thanks loads for getting this far down!! If you know how
it can be tidied (or if it rubbish and unreliable), please
let us know!

Mike
-----Original Message-----
Hi,

I am creating a database for many users. I run a function
that picks up their username (from a dll file).

I have also created a table holding details on some of the
users, this table also holds their status for access
rights.

On open, the username is put into a public variable within
the db. Is there any code I can use to say if the username
is in the [userId] field in the [user] table? I will run
an If statement depending if true or false.

Many thanks,

Mike
.


.
 
Back
Top