Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to create a command button on a data access page that runs a query/macro/module?

5 views
Skip to first unread message

Peter Weinberger

unread,
May 29, 2002, 9:21:54 AM5/29/02
to
Tried DoCmd but I am not sure how to integrate visual basic code into
vb/jscript, so I might have used the wrong syntax....

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

alex_k._angelopoulos_(mvp)

unread,
May 30, 2002, 8:51:36 PM5/30/02
to
Could you post what you are using?

"Peter Weinberger" <peter.we...@comverse.com> wrote in message
news:O3RJOPxBCHA.2572@tkmsftngp05...

Peter Weinberger

unread,
Jun 3, 2002, 2:57:35 AM6/3/02
to

Tx for replying. I wrote the code according to what I understood from
the Access help pages on DoCmd, but several experiments were fruitless,
so I deleted it afterwards. What I need is the right code that connects
to the database and trigger a few queries. I could then append this code
to an existing button.

alex_k._angelopoulos_(mvp)

unread,
Jun 3, 2002, 9:22:05 AM6/3/02
to
That's pretty hard for a non-Access person to do! I could help with converting
something that works in Access over to VBScript, but since I don't know enough
of the Access object model, I don't even have a clue where to start.

Have you tried finding a working in-Access example? If you have a working
database to start with, one of the Access groups could probably help you put
together a reasonable facsimile which can then be turned into script.

"Peter Weinberger" <peter.we...@comverse.com> wrote in message

news:#RLpxvsCCHA.1560@tkmsftngp02...

Peter Weinberger

unread,
Jun 4, 2002, 7:37:52 AM6/4/02
to

[This is how I tried to integrate Visual Basic code into my access page
(without success):]


<SCRIPT language=VBS event=onclick for=Command11>
<!--
Function maskmacro()
On Error GoTo maskmacro_Err

DoCmd.OpenQuery "qrymask", acNormal, acAdd
DoCmd.OpenQuery "qrydelmask", acNormal, acEdit


maskmacro_Exit:
Exit Function

maskmacro_Err:
MsgBox Error$
Resume maskmacro_Exit

End Function


-->
</SCRIPT>

[This is how Access automatically creates code in jscript that
manipulates the database:]

<SCRIPT language=javascript event=onclick for=Command9>
try { MSODSC.CurrentSection.DataPage.Save(); }
[MSODSC.somethingelse.method/function to trigger
query???????????????????????????????????????????????????????????????????
]
catch (e)
{ alert (e.description);}
</SCRIPT>

alex_k._angelopoulos_(mvp)

unread,
Jun 4, 2002, 8:49:46 AM6/4/02
to
Wow... that looks utterly alien.

Here's a minor modification of your first function as a "pure" VBScript; it can
be saved and run interactively as mask.vbs. It is not exactly what you want,
I'm sure, but the key thing is getting you to know the differences in VBScript;
in many ways it is easier than VB or VBA, once you know its idiosyncrasies.

Very simple error control: you can toggle off breaking on errors with "On Error
Resume Next", and turn it back on with "On Error Goto 0". You can't branch on
errors, unfortunately.

You have to instantiate something you are going to use. This is probably a moot
point; you have an object ref to Access or something in your page; for a
client-side script example,we have to instantiate it below. If your object's ID
is "Acc", the code should look an awful lot like this.

On Error Resume Next
Set Acc = GetObject("C:\temp\scripting.mdb")
Acc.Visible = True
Const acAdd = 0, acEdit = 1, acNormal = 0
Acc.DoCmd.OpenQuery "qrymask", acNormal, acAdd
Acc.DoCmd.OpenQuery "qrydelmask", acNormal, acEdit
Acc.UserControl = True
MsgBox Err.Number & Err.Source & Err.Description
Err.Clear

"Peter Weinberger" <peter.we...@comverse.com> wrote in message

news:Oys3Dx7CCHA.2072@tkmsftngp02...

0 new messages