Hi Damon,
Guess what? It's working great and I thank you a thousand times.
I did have the field named curUser, plus I had started with a blank mdb
and
copied only the needed objects. I also started with a basic login form
and
resulting record form.
Once I changed back to userID,it started working. I just kept updating
the
forms until I got back to what I needed in the first place and it still
works! I keep testing it to be sure I didn't dream it.
One quick question though, does each form need it's own strsql variable
name
to set the record source for that form or would have the original one
worked
for all of the tabbed forms? Obviously, I made new one for each form,
but
I
wondered for next time.
Kind Regards,
John Lehmus
Maine, USA
:
Lemme see.
If the curUser is null then you are not assigning a value to it. On
the
logon form is there something that sets the curUser to the value of
the
userID? Have you named the UserID field in your table to CurUser?
That's a
no-no. Change it back to UserID. The curUser variable is just a
container
for the user's id that is established at logon time.
Damon
Hi Damon,
I tried setting both of the field types for curUser in the employee
table
and curUser in the record set to Number / Long Integer. I also reset
the
public statement to "Public CurUser As Long". But, when the called
form
opens
and I check the "On Open" event, the value for variable "curUser" it
still
displays the word Empty.
I'm wondering if maybe the issue here is that I'm using a TabControl
with
3
tabbed subforms, but shouldn't setting the curUser as public cover
these
options too?
Maybe there is a way to "merge" the login to the top of form with
the
TabControl/subforms are located. Thoughts??
Best Regards,
John
~
:
Are you assigning a value to curUser in the logon form? Is it
numeric?
Is
the field UserId in your table numeric?
put a debug.print right after the strsql statement and see if it
reads
correctly.
It works on my end, so not sure where the problem is, usually when
you
get
a parameter box, it doesn't recognize something in your string
statement.
Damon
message
Hi Damon,
Thanks for your time and efforts.
The value now is remembered, but a paramater box pops-up as asks
for
"curUser" expecting me to type something in. CurUser is
remembered
because
I
added a "watch" on both the login forma and the record-set form.
Here is the code set to the "On Load" event:
Sub Form_Load()
Dim strsql As String
strsql = "SELECT RPUserRev.* " & "FROM RPUserRev WHERE
(((RPUserRev.UserID)=
" & curUser & "))"
Me.RecordSource = strsql
Me.Requery
End Sub
Regards,
John_Lehmus
Maine, USA
~~~
:
In your global code module at the top, where it says
Option Compare Database
add
Public curUser As Long
This sets the variable (in this case a long integer) to public
for
use
in
all routines.
If you already have a dim statement for curuser on one of your
forms,
remove
it.
Damon
message
Hi Damon,
I have replaced the info. and I think I'm getting close.
However,
right
after the login screen closes my data form opens and pauses at
a
break-point
I entered. When I check the value for curUser it displays the
word
"Empty".
So It seems that the value of curUser, which does work from
the
login
form,
is not getting passed on to the form that displays the
records.
Is there a way to set the Dim statement or something else so
the
value
will
be remembered?
Cordially,
John_Lehmus
Maine, USA
:
Oops! sorry, the CWO reference was an example. You will
have
to
substitute your own table and field names to make the code
work.
When the form is in design mode, click on the form's Load
Event
and
add
the
VBA code with your own table info.
so the code would be
strsql = "SELECT yourtable.ID, etc (any fields you show on
the
form),
yourtable.UserID " & _
"FROM yourtable WHERE (((yourtable.UserID)= " & [curUser]
&
"))"
As to your question about multiple users, I will have to
defer
to
others
who
have more knowledge of this. All of my dbs are in a single
user
environment. There are a whole bunch of issues that have to
be
addressed
when more than one user is allowed access to a form at the
same
time.
Damon
message
Hi Damon,
Thanks for your reply. Using sql as a record source is
brand
new
for
me.
Will this code allow multiple users to share the same form
at
the
same
time?
The sql code becomes the records source? What do the CWO
letters
refer
to?
Regards,
John
--
John_Lehmus
Maine, USA
:
Using just a main form, you can put the recordsource in
the
form's
load
event, like this example:
(I used a global variable "curUser" that I assign at
logon. -
you
could
also
use CurrentUser if you are using Workgroups. see help)
Dim strsql As String
strsql = "SELECT tblCWO.CWOID, tblCWO.CWODate,
tblCWO.UserID
" &
_
"FROM tblCWO WHERE (((tblCWO.UserID)= " & [curUser] & "))"
Me.RecordSource = strsql
Me.Requery
This restricts the records displayed to just those that
have
the
same
userid
as the current user. Of course, your table would have to
have a
field
for
UserID for this to work.
HTH
Damon
in
message
Hello,
With access running on a network, I want each user to
see
only
their
records
after their login. I have tried using the "one form for
each
user
approach",
but this is for a large group of users and the form may
change
every
so
often.
Is there a safe/secure way to have the [UserID] as a
parent/child
link
to
a
sub-form or maybe a way of using "filters"?
Thanks, and I look forward to your thoughts and ideas.