Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- From: "Bob Barrows" <reb01501@xxxxxxxxxxxxxxx>
- Date: Tue, 15 Dec 2009 10:51:44 -0500
Phillip Windell wrote:
"Bob Barrows" <reb01501@xxxxxxxxxxxxxxx> wrote in messageWell, that is a good thing to do, but ... I tested the code on my
news:u0vjMYSfKHA.4636@xxxxxxxxxxxxxxxxxxxxxxx
the data is not valid. I would prefer to do this in the form's
onSubmit event, like this:
Private Sub frmNewEntry_OnSubmit
'Build error message'
If Document.frmNewEntry.txtTitle.Value = "" Then strErrorMsg =
strErrorMsg _
<snip>
If strErrorMsg <> "" Then
MsgBox strErrorMsg,0,"Errors Encountered!"
window.event.returnValue=false
End if
End Sub
Very good. That fixed the dupes issue. However I tested the error
message part of it by intensionally leaving a field blank,...no error
message like there should have been,....and it posted to the database
with the blank entry instead of canceling the submit. I'm running out
of patients with the stupid thing so I am just going to pull that
block of code out and forget it,...I went into the database with
Access and set those Fields to Required=yes and Allow Zero Length=no
and call it good enough.
machine and it definitely generated an error message when I left the
fields blank ... oh, wait! I left out the line I had to add to
initialize the strErrorMsg variable:
strErrorMsg = ""
If If Document.frmNewEntry.txtTitle.Value = ...
I couldn't get the Parameterized querys to work to replace the SQL
string,..so the SQL String is still there. I'm out of patients there
too I guess. Maybe I took the code sample in those articles too
literal and put things in that were only meant to be place holders
and not actually be in the query's SQL View.
I looked around in Access to figure out what you meant about the
Keys. I've come to the conclusion that I am clueless,...I have no
idea what you mean.
Again, you don't have to do it in Access Design View (although it is
certainly possible using the Indexes toolbar button, or going to
View|Indexes in the menu.). Just create a new query in Design view,
close the Choose Tables dialog without choosing a table, switch to SQL
View and paste this sql in:
CREATE UNIQUE INDEX IX_Events_Unique
ON tblEvents (fldStartDate ASC, fldTitle ASC)
Run it. Then open your table in Design View, open the Indexes dialog and
see what it did.
As for the parameterized sql statement, I took the statement that was
the result of your Response.Write:
INSERT INTO tblEvents (fldTitle, fldStartDate, fldEndDate, fldDetails,
fldApproved) VALUES ('This is a Title', #1/12/2012#, #1/13/2012#, 'This
is a
Description', on)
and pasted it into the SQL View of a query in Access. I then replaced
each of the values with a parameter placeholder like this:
INSERT INTO tblEvents (fldTitle, fldStartDate, fldEndDate, fldDetails,
fldApproved) VALUES ([P1], [P2],[P3],[P4],[P5])
and saved the query as qInsertEvent. Then I replaced your vbscript code
with this:
Dim intID
Dim strTitle
Dim strStartDate
Dim strEndDate
Dim strDetails
Dim strApproved
Dim strSQL
strTitle = CleanIllegalChar(Request.Form.Item("txtTitle"))
strStartDate = cDate(Request.Form.Item("txtStartDate"))
strEndDate = cDate(Request.Form.Item("txtEndDate"))
strDetails = CleanIllegalChar(Request.Form.Item("areaDetails"))
strApproved = Request.Form.Item("chkApproved")
If strApproved = "" then strApproved ="False"
'Incidently, you should validate this data here - especially the date
values ...
objConn.qInsertEvent strTitle, strStartDate, strEndDate, strApproved
objConn.close
It works fine for me. What problem did you run into?
--
HTH,
Bob Barrows
.
- Follow-Ups:
- Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- From: Phillip Windell
- Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- References:
- Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- From: Phillip Windell
- Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- From: Bob Barrows
- Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- From: Phillip Windell
- Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- From: Bob Barrows
- Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- From: Phillip Windell
- Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- From: Bob Barrows
- Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- From: Phillip Windell
- Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- From: Bob Barrows
- Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- From: Phillip Windell
- Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- Prev by Date: Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- Next by Date: Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- Previous by thread: Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- Next by thread: Re: Dup entries when creating a new DB entry (ASP Classic with an MDB file)
- Index(es):
Relevant Pages
|