Difference between 'Call' and 'DoCmd'

craigachan

Registered User.
Local time
Yesterday, 16:27
Joined
Nov 9, 2007
Messages
285
Can someone tell me the difference between 'Call' and 'DoCmd' and how each are executed. For my level of programming, an newbie at that, I've used it interchangably so far without a problem. But I'm beginning to think that there is a difference. I don't want to later have to go back to redo my code down the line. I'm beginning to think that I've been very lucky so far in being able to use it interchangebly and my luck will run out soon.:eek:
 
docmd stands for "document command" (I hope) :)

that's all it is, a command. call is a statement, and it is used to "run" outside procedures. That is, procedures or subprocedures that are located outside of the entity that you are in (either being a subroutine or function, or something else).

I guess the big difference here is that docmd can only handle one request at a time, while call can refer to an entity that is comprised of millions of requests.

What do you mean you have used them interchangeably? That's an interesting statement... ;)
 
I've been calling functions such as: Call Tx.

And I've used: DoCmd.openfunction(Tx)

I don't know if I've just been lucking in my use of these. but I want to learn the difference sooner than later.
 
Well...if you want to use both of those as your example, they do the same thing, so you can never go wrong with them.

You're not lucky. ;) You've just found one of the MANY duplications that are found in every program.

"There's more than one way to skin a cat". Somebody's signature on this forum says that, but I can't remember who it is...
 
docmd (i thought it was Do Commnand) is a general instruction to carry out a range of actions, indicated by the object of the docmd action.

any sub can be invoked merely by stating the name (i think a function requires a call if its not used on the right hand side of an assignment

ie x = myfunc(y)

but Call myfunc(y)

- however if bracketed parameters/arguments are involved then sometimes the word call is necessary for syntax purposes. It is rarely a problem to use the word call, although the precise syntax can be slightly different when using call. I generally include it as I find the code easier to read with call - not sure if it adds a few more clock cycles, but i dont expect its very much different for the compiler

eg
msgbox "mytext", vbcritical, "msgbox title"

but

call msgbox ("mytext", vbcritical, "msgbox title")
 
Simple Software Solutions

Hi all

The way I tend to use DoCmd and Call, especially Call is when you want to run a sub routine with a form vba or a module vba. As sub routines do not return a parameter then the syntax Call tells access to run that particular routine. At typical example is using a Call command to populate the items in a combo box. You can pass parameters to subs but you cannot return them, that's when Private Functions are used

Where as using: X = myFunc(Para1,Para2,etc)

DoCmds as commands that are Access functions, so if I am diong something like running a report or perfroming a sql statement the DoCmd is the way to go.

CodeM:cool:aster
 
Thanks everyone for the nice explainations. I'll keep all of your suggestions for latter consideration.
 

Users who are viewing this thread

Back
Top Bottom