Adding a group by code

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
 
G

Graham Mandeno

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".
 

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