Can someone check my code?

S

Sandy

Hello -

The following code is supposed to just update a user's security settings
when the user's name is highlighted in a listbox (lstUsers). What it's doing
is just adding a user instead of changing the AccessID and ViewID on the
highlighted user. (The highlighted user's info appears in the textboxes.)
What am I doing wrong?

<snip>
If Not lstUsers.Value = "" Then
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblSecurity", dbOpenDynaset)
With rst
.Edit
![Password] = Me.txtPassword
![UserID] = Me.txtUserID
![Active] = Me.txtActive
![AccessID] = Me.txtAccessID
![ViewID] = Me.txtViewID
.Update
End With
If IsLoaded("fmAdmin") Then
Forms!frmAdmin.Requery
Forms!frmAdmin.lstUsers.Requery
End If
<snip>

Any help will be greatly appreciated!
 
N

Nullnvoid

Hi Sandy,

You haven't specified which record to update. "Set rst =
dbs.OpenRecordset("tblSecurity", dbOpenDynaset)" Will just open the whole
table.

Assuming that the user id is a number - the code should read something like:

<snip>
.....
Set rst = dbs.OpenRecordset("SELECT * FROM tblSecurity WHERE UserID = "
& lstUsers.Value, dbOpenDynaset)
if not rst.eof then
With rst
.Edit
![Password] = Me.txtPassword
![UserID] = Me.txtUserID
![Active] = Me.txtActive
![AccessID] = Me.txtAccessID
![ViewID] = Me.txtViewID
.Update
End With
End if
If IsLoaded("fmAdmin") Then
Forms!frmAdmin.Requery
Forms!frmAdmin.lstUsers.Requery
End If

<snip>

Hope that helps
 
S

Sandy

Hi Nullnvoid -

Thank!
--
Sandy


Nullnvoid said:
Hi Sandy,

You haven't specified which record to update. "Set rst =
dbs.OpenRecordset("tblSecurity", dbOpenDynaset)" Will just open the whole
table.

Assuming that the user id is a number - the code should read something like:

<snip>
....
Set rst = dbs.OpenRecordset("SELECT * FROM tblSecurity WHERE UserID = "
& lstUsers.Value, dbOpenDynaset)
if not rst.eof then
With rst
.Edit
![Password] = Me.txtPassword
![UserID] = Me.txtUserID
![Active] = Me.txtActive
![AccessID] = Me.txtAccessID
![ViewID] = Me.txtViewID
.Update
End With
End if
If IsLoaded("fmAdmin") Then
Forms!frmAdmin.Requery
Forms!frmAdmin.lstUsers.Requery
End If

<snip>

Hope that helps
--

Null


Sandy said:
Hello -

The following code is supposed to just update a user's security settings
when the user's name is highlighted in a listbox (lstUsers). What it's doing
is just adding a user instead of changing the AccessID and ViewID on the
highlighted user. (The highlighted user's info appears in the textboxes.)
What am I doing wrong?

<snip>
If Not lstUsers.Value = "" Then
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblSecurity", dbOpenDynaset)
With rst
.Edit
![Password] = Me.txtPassword
![UserID] = Me.txtUserID
![Active] = Me.txtActive
![AccessID] = Me.txtAccessID
![ViewID] = Me.txtViewID
.Update
End With
If IsLoaded("fmAdmin") Then
Forms!frmAdmin.Requery
Forms!frmAdmin.lstUsers.Requery
End If
<snip>

Any help will be greatly appreciated!
 

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

Similar Threads


Top