Proper way to structure Function/Sub Routine and pass variable

G

Guest

Access 2003

I want to have the variable myString to equal the output of a function
(which is a string) called myFunction().

****************************************
The original function is next:

Public Function XYZ(stDatabase As String) As String
....
....
End Function
*****************************************

Therefore which format should I use?

myString = XYZ
- or -
myString = XYZ()
- or -
myString = XYZ(stDatabase As String)

Also, if I want "myString" available to a SubABC()

do I include (one of the above for example)?


Example 1
****************************
SubABC()

myString = XYZ()

End Sub


I want myString to pass into the Function faqChangePassword() below. But
Me!NewPassword is intended to be used only with a form click - I think in a
Class Module? Where as I believe that SubABC() needs to be in a General
Module

Thus, should I merge Function faqChangePassword() into the sub-routine as I
did below? Or leave it as a separate function? If so what type of Module?

Would it be better to use an Input box? to get NewPassword then pass it below?

I just do not know how to structure functions and sub-routines to work
properly.

Please any help?

Dennis

Example 2
****************************
SubABC()

myString = XYZ()

Call faqChangePassword(CurrentUser(), Me!NewPassword, _
myString)

Function faqChangePassword(ByVal strUser As String, ByVal_
strPwd As String, ByVal strOldPwd As String) As Integer

Dim ws As Workspace
Dim usr As User
On Error GoTo err_ChangePassword

Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(strUser)
usr.NewPassword strOldPwd, strPwd

err_ChangePassword:
If Err.Number = 3033 Then
MsgBox "You do not have permission to modify _
passwords. Please contact your system _
administrator."
End If
End Function

End Sub
 
G

Guest

NOTE:

The first sentance should be changes to read:

"I want to have the variable myString to equal the output of a function
(which is a string) called XYZ()."
 
G

Guest

Is there any chance that you might give me the solution?

I do understand the idea of giving a man a fish or teaching a man to fish
for himself. That was pretty clear when you did not reply to my request
yesterday.

That said, I tried real hard to do this myself - Google search and all that.
My goal is NOT to become a VBA programmer and take the next 4-6 hours to
learn much more than I need or even will remember at age 62.

To be sure, your answer can be just "well you loose."

Just think of this though, I have learned wery much by beating my head
against the wall and then obtaining the answer. I am just asking for you to
save us all some time and frustration.

Anyway thanks for your time, knowledge and effort.

:

Dennis
 
G

George Nicholson

I gave you the answer I did because you are asking 4-5 questions that are
intertwined with very *rudimentary* programming concepts that you admit you
don't understand.
Just think of this though, I have learned wery much by beating my head
against the wall and then obtaining the answer. I am just asking for you
to
save us all some time and frustration.

Whose time? Whose frustration? We are all volunteers here. I could take an
hour or two of my time and explain the *rudimentary* programming concepts
that relate to the questions you asked or I could direct you to already
existing documentation that does the same thing.

It is possible that you could get a 100% complete solution to your problem
if you stated what *exactly* you are trying to do: "I want to be able to
click a button and change my password". Dragging in pieces of code that you
copied from somewhere and obviously don't understand is counterproductive,
although I do truly appreciate your attempt to "do it myself".
My goal is NOT to become a VBA programmer and take the next 4-6 hours to
learn much more than I need

If you want to understand the code you found and modify it to work for you,
follow the links & come back.
If you just want a solution, I'd suggest starting another post and clearly
state what your goal is. Leave the code that you found out of it. When you
ask programming questions, you tend to get programming answers... :)

HTH,
 
G

Guest

George,

I am a bit puzzled. Is it incorrect to assume that this forum was supposed
to be a learning place?

Yes there is a fine line between helping by encouraging learning (providing
incremental knowledge victories) vs enabling.

In the MS Excel forums I have learned a lot because of the methods of the
MVP's there - they contribute AND push their "students".

Access VBA is quite different. I.e. there is no message box? That seems to
be consistent.

Is this forum here to honestly help or to provide a platform for the
holier-than-thou's?

You should be ashamed at trying to get off by referring to the *rudimentary*
programming. You are correct no pay - no help.

How much was learned today?

We both wasted time trying to position.

Dennis
 
G

Guest

George,

I am a bit puzzled. Is it incorrect to assume that this forum was supposed
to be a learning place?

Yes there is a fine line between helping by encouraging learning (providing
incremental knowledge victories) vs enabling.

In the MS Excel forums I have learned a lot because of the methods of the
MVP's there - they contribute AND push their "students".

Access VBA is quite different. I.e. there is no message box? That seems to
be consistent.

Is this forum here to honestly help or to provide a platform for the
holier-than-thou's?

You should be ashamed at trying to get off by referring to the *rudimentary*
programming. You are correct no pay - no help.

How much was learned today?

We both wasted time trying to position.

Dennis
 
G

George Nicholson

You asked a series of questions.

I directed you to reference documentation that was better suited than I to
provide the guidance you needed. I honestly thought, (and still do) that was
the best response for the variety of intertwined basic questions you posted
(and, based on experience, for the questions that you very likely be asking
next in order to make what you had do what you wanted).

You obviously didn't like my answer.

I'm sorry you were offended by the form my help took.

I'm sorry that my attempt to assist was unsatisfactory.

I don't think I deserve the "holier than thou" and "you should be ashamed"
remarks, but you are entitled to your opinion.

Good luck to you,
 
L

Larry Linson

"Dennis" wrote
I am a bit puzzled. Is it incorrect to
assume that this forum was supposed
to be a learning place?

Yes, it is. It is not, however, the only place to learn, and it is quite
impractical to provide complete tutorials equivalent to the hundreds of
self-study books and classes in newsgroup responses. There are very good
suggestions for effective use of newsgroups in
http://www.mvps.org/access/netiquette.htm. There are also a vast number of
other "resources" available, for fee or for free -- one I'd suggest is the
online training at Microsoft's Office Online, http://office.microsoft.com...
follow the "Training" links. You'll find others linked in many, many posts
here. I also have a "Resources" section in my not-recently-updated user
group website, http://ntaccess.tripod.com.
. . .
Access VBA is quite different. I.e. there
is no message box? That seems to
be consistent.

Hunh? I think you will find that the VBA6.DLL used in both is identical (it
is also identical to the VBA6.DLL that provided the core language of the
separate Visual Basic 6.0 product). The VBA is identical. It is the object
model that differs between Excel and Access, and since in VBA we spend much
of our time/effort manipulating the object model, it behooves us to invest
some time and effort in learning the object models. BTW, check in the module
window Help for MsgBox statement/function.

What this is not, however, is a source of free consulting or application
development to just write VBA code for anyone who asks.

Larry Linson
Microsoft Access MVP
 
G

Guest

Hi Larry,

Thanks for weighing in. Contrary to both of your opinions, I do know more
about VBA than you think. That said, I am not a programmer and never will
be. If I saw the corrected code I am sure that the time (not more than 2-5
minutes for you folks) will have been well spent for all concerned. There
are thousands out their that would benefit from what you could share with me.

BTW, the VBA may be the same but we both know that Access is constructed
quite differently than Word and Excel which are much more similar.

At the end of the day though, what has been accomplished?

I use all Office products about equally. Over the years the Access
Newsgroup has been the most difficult to obtain meaningful help. The Excel
NG is absolutely the best and they take serious time! Everyone benefits!

After all, if one takes time to share knowledge, it might get in the way of
keeping the help-count index up; therefore just tell the neophytes to "look
in the dictionary."

All I have to do is buy all the reference materials and come here and to
find out which one to look in. Heaven forbid that someone may need to take
some time helping another get through a loop.

Dennis
 
L

Larry Linson

"Dennis" wrote
After all, if one takes time to share
knowledge, it might get in the way of
keeping the help-count index up; there-
fore just tell the neophytes to "look
in the dictionary."

What, pray tell, is a "help-count index"? I trust you are not operating
under the mistaken believe that MVPs have some quota to meet. MVPs are
recognized for their past contributions to the Microsoft software user
community, are not Microsoft employees, and are not paid for their answering
questions in the newsgroups.
All I have to do is buy all the reference
materials and come here and to
find out which one to look in. Heaven
forbid that someone may need to take
some time helping another get through
a loop.

Yes, sometimes it will be necessary to use reference materials that are not
free. However, if you will carefully read my response, I provide links to
the very good _free_ training materials of Office Online, and other sources
that link to much _free_ material.

In fact, however, there is a basis to some of what you complain about. I got
so tired of typing or copying in the same answer to questions about
displaying images in Access (and cluttering the newsgroup archives with many
copies of the same material) that I created a simple example, documentation
explaining it, and set up a website http://accdevel.tripod.com, just so I
could avoid all that unnecessary work. (Many people find it even more useful
than the text I once posted on the subject.)

And, er, aren't we in agreement, but using different words... you say Access
and Excel are different; I said the object models of Access and Excel are
different. I said that the VBA itself is identical, but you have to
manipulate different object models with it -- did you disagree with that?

And, many of the most able and helpful people in newsgroups (both sponsored
newsgroups such as this, or USENET newsgroups such as
comp.databases.ms-access) are also among the busiest. If you want good
answers, it pays to "help them help you".

Larry Linson
Microsoft Access MVP
 

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