Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Decifering Module Code

Status
Not open for further replies.

ryanmc

Programmer
May 31, 2001
41
CA
Hello,

I am having some problems administering a database that;s linked by an OBDC link for it's source information. What's happening is that it's not retreiving all of the information it's suppost to be and I'm getting a problem message which prompts me to debug some code, but I don't understand the code (the database was designed by somebody else). Anyways, I've included the code below and if somebody could clarify what exactly it means, I would really appreciate it.

Note: The code is saved as a module.

Thanks,
Ryan

Public Function LookAtCmd( )
If (Command Like "macro=*") Then
DoCmd.Runacro Mid(Command, Instr(1, Command, "=") +1)
DoCmd.Quit
End If
End Function
 
Did you type that or copy and paste it.

Should be DoCmd.RunMacro Mid.....

All they are doing is changing the name of tha Macro that's being run by manipulating the string.
 
the third line should be DoCmd.RunMacro. I don't know if that's just a typo in your post or what, but essentially, the code is looking at a string variable (Command) and if the string begins with "macro=" then it strips off this portion and runs the macro that is the 'argument' in the Command string.

Example

Command = "macro=Dostuff"
Mid(Command, Instr(1, Command, "=") +1) --> "Dostuff"
DoCmd.RunMacro "Dostuff"

Hope that helps
 
You have a function that looks at a command line parameter.

So when the database is opened it has to have something at the end of the short cut icon like so
macro=xxxxxxxxx

Then it trys to run the macro with this name

DoCmd.Run[red]M[/color]acro Mid(Command, Instr(1, Command, "=") +1)
It is looking for the equal sign in the command line which would be at position 6 and adding one to it to get the Mid starting point (for the macor name) but there is no "length" parameter for the Mid function.
DoCmd.Runacro Mid(Command, InStr(1, Command, "=") + 1, [need a length here])
=Mid(command, start, length)
So it appears to be incorrect.

Find the Desktop Icon that runs this database and copy and paste the entire command line here so we can look at it.

here is one from my desktop, clicking on the Shortcut tab
"C:\Microsoft Office2000\Office\MSACCESS.EXE" "C:\Main Frame\Pinellas.mdb" /X OpenForm


DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
Actually, if you don't specify a length for the Mid() function, it will default to the remaining length of the string, sort of like Right() but specifying the starting point instead of the length
 
This function is checking to see if the string "Command" contains the literal "macro=" at the beginning, and anything else to the right of that literal.

If the expression is true, then the "Docmd.Runacro", which I believe to actually be, "Docmd.RunMacro", runs the macro name returned by parsing it from the Mid function that returns returns the string to the right of the "macro=" value.

I think the problem is with your "Runacro". I am not seeing any other obvious issues.

Gary
gwinn7
 
Mid and Instr are precompiled string functions that are native to MSAccess. I have copied some of the syntax from the help file below - but it is not comprehensive. You should definitely look them up in help - and by all means read the examples. Sometimes the text is confusing but if you read the examples they give you, it makes the meaning clear.

that code is basically testing for a value "macro" or something like "macro" and if it finds that string, it's going into the Macros tab and running a macro called Command. Look in Macros tab and see if there is one called Command. there should be. if so, then single click it and press "design" button. This oughta allow you to see the individual steps that make up this macro - and hopefully help you decipher the steps it is executing.

The crux of solving deciphering this code is to print out the help screens WITH EXAMPLES to the Instr function and the Mid function, and the RunMacro method. That 's the way I usually solve these dilemmas.

I don't know if this helps you at all.

Let us know how you make out.



Syntax for Run Macro is:

DoCmd.RunMacro macroname[, repeatcount][, repeatexpression]

All this does is run some macro named Command

MID
Returns a specific number of characters from a text string starting at the position you specify.

Syntax

MID(text,start_num,num_chars)

Text is the text string from which you want to extract the characters.

Start_num is the position of the first character you want to extract. The first character in Text is 1.

Num_chars specifies how many characters to return from Text.



How much more water would there be in the ocean if it weren't for sponges?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top