Adding a group by code

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

Guest

I am trying to use this posted code

Public Sub CreateUserGroup(strgroupname As String, _
strPID As String)
Dim wrk As DAO.Workspace
Dim grp As DAO.Group

Set wrk = DBEngine(0)
On Error GoTo CreateUserGroupErr
'Create the new group
Set grp = wrk.CreateGroup(strgroupname, strPID)
ws.Groups.Append grp

CreateUserGroupErr:
Set grp = Nothing
Set wrk = Nothing
End Sub

Private Sub Command16_Click()
Call CreateUserGroup("Bassel", 22222)
End Sub

However it doesn't work. Can you help me
Bassel
 
Hi Bassel

On the line I have marked with <<<<<< below, you are using an undeclared
variable named "ws" instead of "wrk".

This is one of the problems with allowing implicitly declared variables.
Every module in your database should have the line "Option Explicit" at the
top. VBA will do this automatically for you if you go to Tools>Options and
select "Require variable declaration".
 
Back
Top