=currentuser()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have secured the database through access and in the query have
userauto:currentuser()


I would like it to grab the userid that is present when the record is input
and keep it at that user.
When I come in and out of the database as different users the field changes
even for records that are already input. I would like the user that was
logged in and add the record to stay with that record.

Also having problem on the report -

Really want it to be if username = fae put Faelynn Kelly if Joe put Joe
Smith and if Mark put Mark Hoffman. What am I doing wrong.
With below code if userauto is Fae it puts in Joe Sidio???

=IIf("[userauto]"='Fae',"FaeLynn","Joe Sidio")

thanks in advance for the help
 
If you've got a field userauto:currentuser() in your query, that implies
it's going to show the current user's id, not the id of the user who saved
the record.

You need to insure that the user id is saved as a field in the table, and
then return that field, not the function.

For your second question, take [userauto] out of the quotes: as it is,
you're comparing the literal string [userauto] to the literal string Fae, so
it'll always be false. You want to compare the value of [userauto] to the
literal string Fae.
 
I have a field in the table called user but not sure what else to do. Got
rid of the userauto in query - not sure what to attach it to or the exact
code.

user=currentuser()

attached it to the before updat of the form - don't want the user to change
if just navigate with buttons through records and not changing data . if
data changed in record or record added want the new user captured.

the second part is working for the name input. thanks

Douglas J. Steele said:
If you've got a field userauto:currentuser() in your query, that implies
it's going to show the current user's id, not the id of the user who saved
the record.

You need to insure that the user id is saved as a field in the table, and
then return that field, not the function.

For your second question, take [userauto] out of the quotes: as it is,
you're comparing the literal string [userauto] to the literal string Fae, so
it'll always be false. You want to compare the value of [userauto] to the
literal string Fae.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


babs said:
I have secured the database through access and in the query have
userauto:currentuser()


I would like it to grab the userid that is present when the record is
input
and keep it at that user.
When I come in and out of the database as different users the field
changes
even for records that are already input. I would like the user that was
logged in and add the record to stay with that record.

Also having problem on the report -

Really want it to be if username = fae put Faelynn Kelly if Joe put Joe
Smith and if Mark put Mark Hoffman. What am I doing wrong.
With below code if userauto is Fae it puts in Joe Sidio???

=IIf("[userauto]"='Fae',"FaeLynn","Joe Sidio")

thanks in advance for the help
 
babs said:
I have a field in the table called user but not sure what else to do. Got
rid of the userauto in query - not sure what to attach it to or the exact
code.

user=currentuser()

attached it to the before updat of the form - don't want the user to
change
if just navigate with buttons through records and not changing data . if
data changed in record or record added want the new user captured.

Include a text box bound to your "user" field on your form, name the text
box "txtUser". Set its locked property to "True". In the Before Update
event of the form put

Me.txtUser=CurrentUser()

This will update every time the record is updated. If you want it to stay
the same from when the record is created then you'd need to use the
NewRecord property (check it out in the help).

HTH - Keith.
www.keithwilby.com
 
When I first come back into the form and Navigate forward (1 to 2) under a
different user I can see the username is set to who put the record in.(or who
looked at it last). Then when I navigate back it gets reset to the present
user. I don't want the username to change if a new person is just navigating
through the records??? Any ideas.

I also posted on Security sorry if this is a problem. I know you said about
newrecord- not sure exactly how to do that or if want to - would like it to
catch the user if the data is modified even on an exisiting record but don't
want it to change if record is just navigated through.


thanks,
Barb
 
Below is the only code I have on the Current event of the Form- think it may
be this autofill not sure how to get around it.



Private Sub Form_Current()
Me![Recordnumber] = Me.CurrentRecord
Call AutoFillNewRecord([Forms]![QuoteEntryForm])
End Sub

thanks for helping
 
babs said:
Below is the only code I have on the Current event of the Form- think it
may
be this autofill not sure how to get around it.


Call AutoFillNewRecord([Forms]![QuoteEntryForm])

This line is calling another procedure. Put your cursor somewhere in
"AutoFillNewRecord", hold <SHIFT> and press <F2> to display the code - what
does it do?

Keith.
www.keithwilby.com
 
It is calling on the Function autofillnewrecord see below:
How can I not make it autofill just the user I guess?????


Function AutoFillNewRecord(F As Form)

Dim RS As DAO.Recordset, C As Control
Dim FillFields As String, FillAllFields As Integer

'On Error Resume Next

'Exit if not on the new record.
If Not F.NewRecord Then Exit Function

'Goto the last record of the form recordset(to auofill form).
Set RS = F.RecordsetClone
RS.MoveLast

'Exit if you cannot move to the last record(no records).
If Err <> 0 Then Exit Function

'Get the list of fields to autofill.
FillFields = ";" & F![AutoFillNewRecordFields] & ";"

'If there is no criteria field, then set flag indicating ALL
'fields should be autofilled.
FillAllFields = Err <> 0

F.Painting = False

'Visit each field on the form.
For Each C In F
'Fill The field if All fields are to be filled Or if the
'....ControlSource field can be found in the Fill Fields list.

If FillAllFields Or InStr(FillFields, ";" & (C.Name) & ";") > 0 Then
C = RS(C.ControlSource)
End If
Next

F.Painting = True

End Function


thanks

Keith Wilby said:
babs said:
Below is the only code I have on the Current event of the Form- think it
may
be this autofill not sure how to get around it.


Call AutoFillNewRecord([Forms]![QuoteEntryForm])

This line is calling another procedure. Put your cursor somewhere in
"AutoFillNewRecord", hold <SHIFT> and press <F2> to display the code - what
does it do?

Keith.
www.keithwilby.com
 
Any ideas??????

babs said:
It is calling on the Function autofillnewrecord see below:
How can I not make it autofill just the user I guess?????


Function AutoFillNewRecord(F As Form)

Dim RS As DAO.Recordset, C As Control
Dim FillFields As String, FillAllFields As Integer

'On Error Resume Next

'Exit if not on the new record.
If Not F.NewRecord Then Exit Function

'Goto the last record of the form recordset(to auofill form).
Set RS = F.RecordsetClone
RS.MoveLast

'Exit if you cannot move to the last record(no records).
If Err <> 0 Then Exit Function

'Get the list of fields to autofill.
FillFields = ";" & F![AutoFillNewRecordFields] & ";"

'If there is no criteria field, then set flag indicating ALL
'fields should be autofilled.
FillAllFields = Err <> 0

F.Painting = False

'Visit each field on the form.
For Each C In F
'Fill The field if All fields are to be filled Or if the
'....ControlSource field can be found in the Fill Fields list.

If FillAllFields Or InStr(FillFields, ";" & (C.Name) & ";") > 0 Then
C = RS(C.ControlSource)
End If
Next

F.Painting = True

End Function


thanks

Keith Wilby said:
babs said:
Below is the only code I have on the Current event of the Form- think it
may
be this autofill not sure how to get around it.


Call AutoFillNewRecord([Forms]![QuoteEntryForm])

This line is calling another procedure. Put your cursor somewhere in
"AutoFillNewRecord", hold <SHIFT> and press <F2> to display the code - what
does it do?

Keith.
www.keithwilby.com
 
Back
Top