VBScript problem

R

Rosebud

I converted an Access data entry form to a DAP. The user adds a new record
by completing the form and pressing the Submit button. The onclick event of
the button should verify certain fields and then add the record to the
database. The verification is working fine but I can't get the record added
to the database. I'm a rookie at this with no VBScript experience so I'm
sure I'm just coding it wrong. Here's a sample of the code that includes the
section I'm having problems with:

<BUTTON id=SubmitMe
style="Z-INDEX: 33; LEFT: 5.791in; WIDTH: 0.5in; POSITION: absolute; TOP:
2.164in; HEIGHT: 0.28in"
tabIndex=12 MsoTextAlign="General">Submit</BUTTON>
<SCRIPT language=vbscript event=onclick for=SubmitMe>
intErrorCount=0
If DropDownList0.value="" then
MsgBox "Please enter a name in the YOUR NAME field.",0,"Validation Error"
intErrorCount=1
End If
If ClientSelect.value="" then
MsgBox "Please select a client.",0,"Validation Error"
intErrorCount=1
End If
If RequestDescription.value="" then
MsgBox "Please enter a description for your request.",0,"Validation Error"
intErrorCount=1
End If
If DropDownList2.value="" then
MsgBox "Please select who we should contact - You or The
Client.",0,"Validation Error"
intErrorCount=1
End If
If DropDownList2.value="The Client" and ContactName.value="" then
MsgBox "You must provide a Contact Name if you want us to contact the
client.",0,"Validation Error"
intErrorCount=1
End If
If DropDownList2.value="The Client" and (Telephone.value="" and
Text1.value="")then
MsgBox "You must provide either a Telephone number or email address if
you want us to contact the client.",0,"Validation Error"
intErrorCount=1
End If
If intErrorCount=0 then
ADODB.Recordset.Update
MsgBox "Request Submitted to Standards and Practices.",0,"Confirmation
Message"
End If
</SCRIPT>
 
K

Ken Snell \(MVP\)

I don't see anywhere in your script that you define what the
"ADODB.Recordset" object is?
 
R

Rosebud

As I said, I'm a rookie so forgive what I'm sure is a stupid question. What
would the object be? The name of the table? And where/how would I define it?
 
K

Ken Snell \(MVP\)

Unfortunately, I cannot say what the correct object would be because I don't
know the details about your page, etc. Are you wanting to update the record
that is being displayed on the Data Access Page when you click the button?
 
R

Rosebud

Yes. The user is actually adding a new record.

Ken Snell (MVP) said:
Unfortunately, I cannot say what the correct object would be because I don't
know the details about your page, etc. Are you wanting to update the record
that is being displayed on the Data Access Page when you click the button?
 
K

Ken Snell \(MVP\)

Are the elements bound to fields in the DAP's recordset? If yes, you must
explicitly save the new record using VBScript step:
MSODSC.DataPages(0).Save


If the elements are not bound to fields in the DAP's recordset, here is some
sample VBScript that will add data to a recordset, based on the values
entered into elements on a DAP:

SAMPLE VISUAL BASIC SCRIPT CODE TO OPEN A RECORDSET TO A TABLE,
AND TO ADD A NEW RECORD TO THAT TABLE BASED ON A VALUE THAT IS
ON THE DAP.



dim rst


Dim vbs_adParamInput
Dim vbs_adInteger
dim vbs_adCmdStoredProc
dim vbs_adCmdText
Dim vbs_adOpenDynamic
Dim vbs_adLockOptimistic
Dim vbs_adOpenForwardOnly
Dim vbs_adOpenKeyset
Dim vbs_adOpenStatic
Dim vbs_adLockReadOnly
Dim vbs_adLockPessimistic


vbs_adParamInput = 1
vbs_adInteger=3
vbs_adCmdStoredProc=4
vbs_adCmdText=1
vbs_adOpenDynamic=2
vbs_adLockOptimistic=3
vbs_adOpenForwardOnly=0
vbs_adOpenKeyset=1
vbs_adOpenStatic=3
vbs_adLockReadOnly=1
vbs_adLockPessimistic=2



set rst=createobject("adodb.recordset")

rst.Open "tblwellattributedetails", msodsc.Connection, _
vbs_adOpenDynamic, vbs_adLockOptimistic

rst.AddNew
rst.Fields("wellid").Value = wellid.value
rst.Fields("WellAttrTypeID").Value = 12
rst.Fields("WellAttrValue").Value = True
rst.Update

rst.Close
Set rst = Nothing
 

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