Msg displayed if user is not the PM in form

D

deb

I have a button (Find Record) on a popup form that brings up a list of
records to choose from. When a record is clicked it finds and displays the
particular record in the main form form. (see code below)

When a project manager displays a record, he sometimes displays and edits a
record that does not belong to him.

How can I check to see if the user is the project manager and if he is not
the project manager display a message "This record belongs to Mike Smith, are
you sure you want to edit?" with an ok cancel option.

I have a PM table that has userID and Project manager name.

Private Sub ShowRecord4_Click()
Dim Rst As DAO.Recordset
' Store the recordset for the form.
Set Rst = Forms!f4ShipmentEdit.RecordsetClone

' Locate the record for the selected.
Rst.FindFirst "ShipmentID= " & List4

' Set the form's Bookmark property to move to the record.
Forms!f4ShipmentEdit.Bookmark = Rst.Bookmark

' Close the dialog box.
DoCmd.Close acForm, "f4ShipmentEditGoTo"
End Sub
 
M

Mark A. Sam

Hello Deb.

If this is just for ID purposes and not for security you could place an
unbound combo box on the form with all the PM's names to choose from. The
userid would be in the first column. When the name is selected, filter the
selection list Described in the first paragraph of your message) by that
selection.

I would change the rowsource if it is a listbox or the recordsource if it is
a form, on the AfterUpdate event of the combobox.

Something like this:

Private Sub cboPms_AfterUpdate()

If IsNull([cboPms]) Or [cboPms] = "" Then
[lstPms].RowSource = "SELECT PMs.UserID, PMs.[PM Name] FROM PMs;"
Else
[lstPms].RowSource = "SELECT PMs.UserID, PMs.[PM Name] FROM PMs WHERE
PMs.UserID= " & [cboPms] & ";"
End If


End Sub

Where PMs is a table, [cboPMs] is a combobox and [lstPMs] is a listbox

God Bless,

If this is a security issue, then you may have to set up a login system,
where the user is logged in and his userid is saved in a global variable.
You could then check that against the table field in your code.

God Bless,

Mark A. Sam
 
D

deb

Thank you for your response. I don't think this will work.

I have a button that opens a pop up form. The form contains a selection of
records. The PM selects a record and the record displays in a master form.

I need to be able to read the user NT id that the user is log in as and
compare this to the PM to see if it is the correct person for this record.



--
deb


Mark A. Sam said:
Hello Deb.

If this is just for ID purposes and not for security you could place an
unbound combo box on the form with all the PM's names to choose from. The
userid would be in the first column. When the name is selected, filter the
selection list Described in the first paragraph of your message) by that
selection.

I would change the rowsource if it is a listbox or the recordsource if it is
a form, on the AfterUpdate event of the combobox.

Something like this:

Private Sub cboPms_AfterUpdate()

If IsNull([cboPms]) Or [cboPms] = "" Then
[lstPms].RowSource = "SELECT PMs.UserID, PMs.[PM Name] FROM PMs;"
Else
[lstPms].RowSource = "SELECT PMs.UserID, PMs.[PM Name] FROM PMs WHERE
PMs.UserID= " & [cboPms] & ";"
End If


End Sub

Where PMs is a table, [cboPMs] is a combobox and [lstPMs] is a listbox

God Bless,

If this is a security issue, then you may have to set up a login system,
where the user is logged in and his userid is saved in a global variable.
You could then check that against the table field in your code.

God Bless,

Mark A. Sam




deb said:
I have a button (Find Record) on a popup form that brings up a list of
records to choose from. When a record is clicked it finds and displays
the
particular record in the main form form. (see code below)

When a project manager displays a record, he sometimes displays and edits
a
record that does not belong to him.

How can I check to see if the user is the project manager and if he is not
the project manager display a message "This record belongs to Mike Smith,
are
you sure you want to edit?" with an ok cancel option.

I have a PM table that has userID and Project manager name.

Private Sub ShowRecord4_Click()
Dim Rst As DAO.Recordset
' Store the recordset for the form.
Set Rst = Forms!f4ShipmentEdit.RecordsetClone

' Locate the record for the selected.
Rst.FindFirst "ShipmentID= " & List4

' Set the form's Bookmark property to move to the record.
Forms!f4ShipmentEdit.Bookmark = Rst.Bookmark

' Close the dialog box.
DoCmd.Close acForm, "f4ShipmentEditGoTo"
End Sub
 
M

Mark A. Sam

You put the combox on the popup form. I will work unless the popup form is
in datasheet view. If you are selecting by record instead of a listbox,
then set the recordsource of the popup form. Then only that PM's records
will display.


deb said:
Thank you for your response. I don't think this will work.

I have a button that opens a pop up form. The form contains a selection
of
records. The PM selects a record and the record displays in a master
form.

I need to be able to read the user NT id that the user is log in as and
compare this to the PM to see if it is the correct person for this record.



--
deb


Mark A. Sam said:
Hello Deb.

If this is just for ID purposes and not for security you could place an
unbound combo box on the form with all the PM's names to choose from.
The
userid would be in the first column. When the name is selected, filter
the
selection list Described in the first paragraph of your message) by that
selection.

I would change the rowsource if it is a listbox or the recordsource if it
is
a form, on the AfterUpdate event of the combobox.

Something like this:

Private Sub cboPms_AfterUpdate()

If IsNull([cboPms]) Or [cboPms] = "" Then
[lstPms].RowSource = "SELECT PMs.UserID, PMs.[PM Name] FROM PMs;"
Else
[lstPms].RowSource = "SELECT PMs.UserID, PMs.[PM Name] FROM PMs WHERE
PMs.UserID= " & [cboPms] & ";"
End If


End Sub

Where PMs is a table, [cboPMs] is a combobox and [lstPMs] is a listbox

God Bless,

If this is a security issue, then you may have to set up a login system,
where the user is logged in and his userid is saved in a global variable.
You could then check that against the table field in your code.

God Bless,

Mark A. Sam




deb said:
I have a button (Find Record) on a popup form that brings up a list of
records to choose from. When a record is clicked it finds and
displays
the
particular record in the main form form. (see code below)

When a project manager displays a record, he sometimes displays and
edits
a
record that does not belong to him.

How can I check to see if the user is the project manager and if he is
not
the project manager display a message "This record belongs to Mike
Smith,
are
you sure you want to edit?" with an ok cancel option.

I have a PM table that has userID and Project manager name.

Private Sub ShowRecord4_Click()
Dim Rst As DAO.Recordset
' Store the recordset for the form.
Set Rst = Forms!f4ShipmentEdit.RecordsetClone

' Locate the record for the selected.
Rst.FindFirst "ShipmentID= " & List4

' Set the form's Bookmark property to move to the record.
Forms!f4ShipmentEdit.Bookmark = Rst.Bookmark

' Close the dialog box.
DoCmd.Close acForm, "f4ShipmentEditGoTo"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top