By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,965 Members | 2,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,965 IT Pros & Developers. It's quick & easy.

I was planning to use this code to add users in A97...

P: n/a
MLH
I have not yet tried running this code in Access 97. It was
ported from Access 2.0. It fails to compile, failing on the line
xxxxxxxxxxxxxxxxxxx

Function MakeUsersFromTable(TableName As String, GroupName As String)
'************************************************* ********************
' Accepts TableName, GroupName
'
' Returns "Users Added" if successful. Otherwise, "Users Not Added".
'
' The object here is to have a table with three fields feed a data
' stream to this procedure. The three fields represent user name,
' personal id (PID) and password. The procedure churns out a new user
' for each record in the table.
'************************************************* ********************
On Error GoTo Err291

Dim MyWorkSpace As Workspace, MyDatabase As Database
Dim MyRecordSet As Recordset, MyUser As USER, MyGroup As Group
Set MyWorkSpace = DBEngine.Workspaces(0)
Set MyDatabase = DBEngine.Workspaces(0).Databases(0)
Set MyRecordSet = MyDatabase.OpenRecordset(TableName, DB_OPEN_DYNASET)
MyRecordSet.MoveFirst

Do Until MyRecordSet.EOF
Set MyUser = MyWorkSpace.CreateUser(MyRecordSet!UserName,
MyRecordSet!PID, MyRecordSet!Password) ' name, PID and ZLS password
MyWorkSpace.Users.Append MyUser
Set MyUser = MyWorkSpace.CreateUser(MyRecordSet![UserName]) ' not
knowing this line needed 2B here cost me an entire day!
MyWorkSpace.Groups(GroupName).Users.Append MyUser
MyRecordSet.MoveNext
LoopMark:
Loop
MakeUsersFromTable = "Users Added"

Exit291:
Exit Function

Err291:
If Err = 3390 Then
MsgBox MyRecordSet.UserName & " is already a user! Make a note of
it.", 64, "User Exists!" & " - " & MyApp$ & ", rev. " & MY_VERSION$
GoTo LoopMark ' could put Resume Next in here
End If
MakeUsersFromTable = "Users Not Added"
MsgBox Error$ & Err, 16, MyApp & ", version " & MY_VERSION$
GoTo Exit291

End Function
It fails saying "Method or data member not found when compiling
MsgBox MyRecordSet.UserName (under Err291: label).
Is this easily fixed?
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
MLH
Big oops!

I changed the following line...

MsgBox MyRecordSet.UserName & " is already a user! Make a note of
it.", 64, "User Exists!" & " - " & MyApp$ & ", rev. " & MY_VERSION$

to

MsgBox MyRecordSet!UserName & " is already a user! Make a note of
it.", 64, "User Exists!" & " - " & MyApp$ & ", rev. " & MY_VERSION$

and now it compiles fine. Just a small syntax error. Replacing period
with bang did the trick. I'm assuming the code will run. Do any of you
recommend a better alternative coding strategy?
Nov 13 '05 #2

P: n/a
MLH <CR**@NorthState.net> wrote in
news:r0********************************@4ax.com:
Big oops!

I changed the following line...

MsgBox MyRecordSet.UserName & " is already a user! Make a note of
it.", 64, "User Exists!" & " - " & MyApp$ & ", rev. " &
MY_VERSION$

to

MsgBox MyRecordSet!UserName & " is already a user! Make a note of
it.", 64, "User Exists!" & " - " & MyApp$ & ", rev. " &
MY_VERSION$

and now it compiles fine. Just a small syntax error. Replacing
period with bang did the trick. I'm assuming the code will run. Do
any of you recommend a better alternative coding strategy?


Well, you have to understand that in recordsets, . denotes a
property, and ! denotes a member of the default collection
(Fields()).

The promiscuous intermingling of . and ! is something that is
encouraged by the implicit function wrappers around controls in
forms/reports, and I think is a bad practice, precisely because it
leads to problems like this when you try to transfer the practice
outside its domain of applicability.

Of course, Access 2 was much worse about that, if I remember
correctly.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.