Script on Data Access Page

G

Guest

I've converted a form over to a DAP. The form has a submit button which
should save the record and display a confirmation message box. The record is
being saved but the message is not working. I've put the code for the message
box in the afterupdate event because eventually I want to put some
verifications in here as well. I'm a total rookie at scripting and cannot
get this to work! Can someone review the code below and tell me what I'm
doing wrong? Thanks.

<SCRIPT language=javascript event=onclick for=SubmitMe>
try { if (MSODSC.DataPages.Count > 0)
if (MSODSC.CurrentSection == null)
MSODSC.DataPages(0).Update();
else
MSODSC.CurrentSection.DataPage.Recordset.Update;}
catch (e)
{ alert (e.description);}
</SCRIPT>

<SCRIPT language=vbscript event=onafterupdate for=SubmitMe>
<!--
' Display a confirmation message
Dim MyResponse, ConfMsg
ConfMsg = "Request Submitted."
MyResponse = MsgBox(ConfMsg,0,"Confirmation Message")

-->
</SCRIPT>
 
G

Guest

Didn't work. I'm not getting an error message or anything. It's as if that
section of code is not even being run. Does it have something to do with
being tied to the AfterUpdate event of the Submit button maybe?
 
K

Ken Snell \(MVP\)

The script that you have right now is supposed to run in the AfterUpdate
event of an element named SubmitMe. If SubmitMe is a button, you should use
the Click event.
 
G

Guest

Okay, that makes sense. When I click the SubmitMe button, I want to validate
certain elements (i.e. make sure the name field has a name entered), save the
record and then display the msgbox. So would something like this work:

<SCRIPT language=vbscript event=onclick for=SubmitMe>
<!--
If Name="" then
Beep
MsgBox "Invalid Name",0,"Validation Error"
Else
DoCmd.Update
Msg "Request Submitted",0,"Confirmation Message"
End if
 
K

Ken Snell \(MVP\)

What is "Name" -- an element? a field? a variable? (Note: not good to use it
as the name of anything -- Name means special things to ACCESS.) Most
likely, your reference to whatever it is needs a different syntax, but
cannot say what until I know what it is.

Also, there are no DoCmd methods in VBScript. You must use the Save action
of the MSODC.Recordset object.

--

Ken Snell
<MS ACCESS MVP>
 
G

Guest

I was just using "Name" as an example. The field in the table is called
"SubmittedBy". The element on the DAP is called "DropDownList0". Help with
syntax is exactly what I need. I may be over my head on this. Can you point
me to a good resource to learn about MSODC?
 
K

Ken Snell \(MVP\)

You need to use the name of the element in the script:


If DropDownList0.Value="" then
Beep
MsgBox "Invalid Name",0,"Validation Error"
Else
MSODC.DataPages(0).Save
Msg "Request Submitted",0,"Confirmation Message"
End if



I don't know of any good papers / sites for DAPs. They have not been
well-documented nor widely used; in fact, ACCESS 2007 does not support the
creation/editing of DAPs any more, so they're being deprecated.

MSDN has some articles that may be helpful. Go to this page:
http://msdn2.microsoft.com/en-us/library/default.aspx

On left side menu, select "Office Solutions Development", then "Microsoft
Office XP", then "Access 2002", then "Technical Articles". You will find
some articles there about DAPs.

--

Ken Snell
<MS ACCESS MVP>
 
G

Guest

Thanks so much!

Ken Snell (MVP) said:
You need to use the name of the element in the script:


If DropDownList0.Value="" then
Beep
MsgBox "Invalid Name",0,"Validation Error"
Else
MSODC.DataPages(0).Save
Msg "Request Submitted",0,"Confirmation Message"
End if



I don't know of any good papers / sites for DAPs. They have not been
well-documented nor widely used; in fact, ACCESS 2007 does not support the
creation/editing of DAPs any more, so they're being deprecated.

MSDN has some articles that may be helpful. Go to this page:
http://msdn2.microsoft.com/en-us/library/default.aspx

On left side menu, select "Office Solutions Development", then "Microsoft
Office XP", then "Access 2002", then "Technical Articles". You will find
some articles there about DAPs.
 

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