User filtering

  • Thread starter Thread starter Pwyd
  • Start date Start date
P

Pwyd

Hi, i'd like to get the login name for any given user (we use a shortname for
our network, consisting of their first initial and last name) and use that to
filter out all the records except the ones that have that user's name on
them. I'm not worried about all of the security issues that may be involved
in this, unless they're very major or would allow them to do something they
normally would not be able to, if they'd simply opened the database on their
own machine without filters.

What function does one use to get the name of the login for the current
machine?
And how would one concatenate a string to make that name equivalent to whats
stored in the form?
 
Here is a function that will return the current user's login name. Put it in
a standard module by itself:

Private Declare Function GetUserNameA Lib "Advapi32" (ByVal strN As String,
ByRef intN As Long) As Long
Public Function GetUserID()

Dim Buffer As String * 20
Dim Length As Long
Dim lngresult As Long, userid As String

Length = 20

lngresult = GetUserNameA(Buffer, Length)
If lngresult <> 0 Then
GetUserID = Left(Buffer, Length - 1)
Else
GetUserID = "xxxxxxx"
End If

End Function

Add a text box to your form. It can be hidden if you like. Call the
function from the textbox's Control Source property:

=GetUserID()

Be sure to use the = and the () or it will not work.

Instead of using form filtering, use a query based on your table as the
form's record source. Then for the field that has the user's name put the
name of the form and control in the criteria row like this:
[Forms]![NameOfForm]![NameOfTextBox]

The query will now only return record for the logged in user.
 
Thanks klatuu!


Klatuu said:
Here is a function that will return the current user's login name. Put it in
a standard module by itself:

Private Declare Function GetUserNameA Lib "Advapi32" (ByVal strN As String,
ByRef intN As Long) As Long
Public Function GetUserID()

Dim Buffer As String * 20
Dim Length As Long
Dim lngresult As Long, userid As String

Length = 20

lngresult = GetUserNameA(Buffer, Length)
If lngresult <> 0 Then
GetUserID = Left(Buffer, Length - 1)
Else
GetUserID = "xxxxxxx"
End If

End Function

Add a text box to your form. It can be hidden if you like. Call the
function from the textbox's Control Source property:

=GetUserID()

Be sure to use the = and the () or it will not work.

Instead of using form filtering, use a query based on your table as the
form's record source. Then for the field that has the user's name put the
name of the form and control in the criteria row like this:
[Forms]![NameOfForm]![NameOfTextBox]

The query will now only return record for the logged in user.
--
Dave Hargis, Microsoft Access MVP


Pwyd said:
Hi, i'd like to get the login name for any given user (we use a shortname for
our network, consisting of their first initial and last name) and use that to
filter out all the records except the ones that have that user's name on
them. I'm not worried about all of the security issues that may be involved
in this, unless they're very major or would allow them to do something they
normally would not be able to, if they'd simply opened the database on their
own machine without filters.

What function does one use to get the name of the login for the current
machine?
And how would one concatenate a string to make that name equivalent to whats
stored in the form?
 
Klatuu i have a question. I was going to add the filter based on these user
names. Here's the question: When a user tries to make a new, blank record,
will it immediately be filtered out because it lacks the user's name, or it
will wait until the user completes the record before applying the filter?

Klatuu said:
Here is a function that will return the current user's login name. Put it in
a standard module by itself:

Private Declare Function GetUserNameA Lib "Advapi32" (ByVal strN As String,
ByRef intN As Long) As Long
Public Function GetUserID()

Dim Buffer As String * 20
Dim Length As Long
Dim lngresult As Long, userid As String

Length = 20

lngresult = GetUserNameA(Buffer, Length)
If lngresult <> 0 Then
GetUserID = Left(Buffer, Length - 1)
Else
GetUserID = "xxxxxxx"
End If

End Function

Add a text box to your form. It can be hidden if you like. Call the
function from the textbox's Control Source property:

=GetUserID()

Be sure to use the = and the () or it will not work.

Instead of using form filtering, use a query based on your table as the
form's record source. Then for the field that has the user's name put the
name of the form and control in the criteria row like this:
[Forms]![NameOfForm]![NameOfTextBox]

The query will now only return record for the logged in user.
--
Dave Hargis, Microsoft Access MVP


Pwyd said:
Hi, i'd like to get the login name for any given user (we use a shortname for
our network, consisting of their first initial and last name) and use that to
filter out all the records except the ones that have that user's name on
them. I'm not worried about all of the security issues that may be involved
in this, unless they're very major or would allow them to do something they
normally would not be able to, if they'd simply opened the database on their
own machine without filters.

What function does one use to get the name of the login for the current
machine?
And how would one concatenate a string to make that name equivalent to whats
stored in the form?
 
Hey Klatuu, i've put it in a module on its own, saved it, then put a text box
as you suggested into the form. I left it visible, just to see its result,
and its outputting #Name?

Is this because i'm missing some add-in code module in the database, or have
i done something incorrectly?


Klatuu said:
Here is a function that will return the current user's login name. Put it in
a standard module by itself:

Private Declare Function GetUserNameA Lib "Advapi32" (ByVal strN As String,
ByRef intN As Long) As Long
Public Function GetUserID()

Dim Buffer As String * 20
Dim Length As Long
Dim lngresult As Long, userid As String

Length = 20

lngresult = GetUserNameA(Buffer, Length)
If lngresult <> 0 Then
GetUserID = Left(Buffer, Length - 1)
Else
GetUserID = "xxxxxxx"
End If

End Function

Add a text box to your form. It can be hidden if you like. Call the
function from the textbox's Control Source property:

=GetUserID()

Be sure to use the = and the () or it will not work.

Instead of using form filtering, use a query based on your table as the
form's record source. Then for the field that has the user's name put the
name of the form and control in the criteria row like this:
[Forms]![NameOfForm]![NameOfTextBox]

The query will now only return record for the logged in user.
--
Dave Hargis, Microsoft Access MVP


Pwyd said:
Hi, i'd like to get the login name for any given user (we use a shortname for
our network, consisting of their first initial and last name) and use that to
filter out all the records except the ones that have that user's name on
them. I'm not worried about all of the security issues that may be involved
in this, unless they're very major or would allow them to do something they
normally would not be able to, if they'd simply opened the database on their
own machine without filters.

What function does one use to get the name of the login for the current
machine?
And how would one concatenate a string to make that name equivalent to whats
stored in the form?
 
Also, i'm not sure i'm being clear, or i don't understand your method here:
you stated that instead of form filtering.... logged in user.
If the form that i'm using has this query as a record source instead of the
proper table as its record source, where will it acquire the records from?

Or am i building a query based on the two tables together?


Klatuu said:
Here is a function that will return the current user's login name. Put it in
a standard module by itself:

Private Declare Function GetUserNameA Lib "Advapi32" (ByVal strN As String,
ByRef intN As Long) As Long
Public Function GetUserID()

Dim Buffer As String * 20
Dim Length As Long
Dim lngresult As Long, userid As String

Length = 20

lngresult = GetUserNameA(Buffer, Length)
If lngresult <> 0 Then
GetUserID = Left(Buffer, Length - 1)
Else
GetUserID = "xxxxxxx"
End If

End Function

Add a text box to your form. It can be hidden if you like. Call the
function from the textbox's Control Source property:

=GetUserID()

Be sure to use the = and the () or it will not work.

Instead of using form filtering, use a query based on your table as the
form's record source. Then for the field that has the user's name put the
name of the form and control in the criteria row like this:
[Forms]![NameOfForm]![NameOfTextBox]

The query will now only return record for the logged in user.
--
Dave Hargis, Microsoft Access MVP


Pwyd said:
Hi, i'd like to get the login name for any given user (we use a shortname for
our network, consisting of their first initial and last name) and use that to
filter out all the records except the ones that have that user's name on
them. I'm not worried about all of the security issues that may be involved
in this, unless they're very major or would allow them to do something they
normally would not be able to, if they'd simply opened the database on their
own machine without filters.

What function does one use to get the name of the login for the current
machine?
And how would one concatenate a string to make that name equivalent to whats
stored in the form?
 
nevermind. i've got it. Thanks Klatuu


Pwyd said:
Also, i'm not sure i'm being clear, or i don't understand your method here:
you stated that instead of form filtering.... logged in user.
If the form that i'm using has this query as a record source instead of the
proper table as its record source, where will it acquire the records from?

Or am i building a query based on the two tables together?


Klatuu said:
Here is a function that will return the current user's login name. Put it in
a standard module by itself:

Private Declare Function GetUserNameA Lib "Advapi32" (ByVal strN As String,
ByRef intN As Long) As Long
Public Function GetUserID()

Dim Buffer As String * 20
Dim Length As Long
Dim lngresult As Long, userid As String

Length = 20

lngresult = GetUserNameA(Buffer, Length)
If lngresult <> 0 Then
GetUserID = Left(Buffer, Length - 1)
Else
GetUserID = "xxxxxxx"
End If

End Function

Add a text box to your form. It can be hidden if you like. Call the
function from the textbox's Control Source property:

=GetUserID()

Be sure to use the = and the () or it will not work.

Instead of using form filtering, use a query based on your table as the
form's record source. Then for the field that has the user's name put the
name of the form and control in the criteria row like this:
[Forms]![NameOfForm]![NameOfTextBox]

The query will now only return record for the logged in user.
--
Dave Hargis, Microsoft Access MVP


Pwyd said:
Hi, i'd like to get the login name for any given user (we use a shortname for
our network, consisting of their first initial and last name) and use that to
filter out all the records except the ones that have that user's name on
them. I'm not worried about all of the security issues that may be involved
in this, unless they're very major or would allow them to do something they
normally would not be able to, if they'd simply opened the database on their
own machine without filters.

What function does one use to get the name of the login for the current
machine?
And how would one concatenate a string to make that name equivalent to whats
stored in the form?
 
Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
 
Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
 
Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
 
Back
Top