473,416 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Simple htm vbscript snippet for appending database record

Does anyone have a simple html vbscript or other type of snippet they
can share that appends a record to a access database via ADO or DAO?
I would like to allow users that don't have Microsoft Access a way of
adding records to a access database from a simple web page. I don't
want to have to setup ODBC or anything like that I just want to put
the web page on the network for anyone to access. Most of the users
would use the local access front end but those who don't have Access
would just open up the .htm file and post the information from the web
form. If anyone has the time to cut & paste an example that would be
great.
Nov 13 '05 #1
9 12299
On 23 Nov 2004 11:33:29 -0800, so**********@netzero.net (Pete) wrote:
Does anyone have a simple html vbscript or other type of snippet they
can share that appends a record to a access database via ADO or DAO?
I would like to allow users that don't have Microsoft Access a way of
adding records to a access database from a simple web page. I don't
want to have to setup ODBC or anything like that I just want to put
the web page on the network for anyone to access. Most of the users
would use the local access front end but those who don't have Access
would just open up the .htm file and post the information from the web
form. If anyone has the time to cut & paste an example that would be
great.


Hi
Do you mean local / networked database?
If script is not disabled you can run a simple .vbs file such as

Set conn = WScript.CreateObject("ADODB.Connection")
MdbFilePath = "C:\db1.mdb"
conn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" &
MdbFilePath & ";"

SQL = "INSERT INTO Table1 ( colour, path ) SELECT [colour]+1 AS Expr1,
[path] & '1' AS Expr2 FROM Table1;"

conn.Execute(SQL)
conn.Close

Or did you mean a server database, using ASP? Code would be similar,
something like

<%
Set conn = server.CreateObject("ADODB.Connection")

MdbFilePath = Server.MapPath("db1.mdb")
conn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" &
MdbFilePath & ";"

SQL = "INSERT INTO Table1 ( colour, path ) SELECT [colour]+1
AS Expr1, [path] & '1' AS Expr2 FROM Table1;"

conn.Execute(SQL)
conn.Close
%>

David
Nov 13 '05 #2
Yes it would be a network backend .mdb database. That's exactly the
syntax I'm looking for but I need to embed this in a simple .html file
with a textbox and button so that users can insert the record to the
mdb via the vbscript. Would you happen to have the syntax to activate
this from a web page? Any method will do (vbscript asp ...) Thanks
Nov 13 '05 #3
On 24 Nov 2004 10:22:19 -0800, so**********@netzero.net (Pete) wrote:
Yes it would be a network backend .mdb database. That's exactly the
syntax I'm looking for but I need to embed this in a simple .html file
with a textbox and button so that users can insert the record to the
mdb via the vbscript. Would you happen to have the syntax to activate
this from a web page? Any method will do (vbscript asp ...) Thanks


Hi
See the example at
http://www.4guysfromrolla.com/webtec...tml#postadlink
which gives generic code for database insert via HTML form and ASP.
David

Nov 13 '05 #4

"Pete" <so**********@netzero.net> wrote in message
news:8f**************************@posting.google.c om...
Yes it would be a network backend .mdb database. That's exactly the
syntax I'm looking for but I need to embed this in a simple .html file
with a textbox and button so that users can insert the record to the
mdb via the vbscript. Would you happen to have the syntax to activate
this from a web page? Any method will do (vbscript asp ...) Thanks

If you need only a single textbox, to get data from the user, then using a
stand-alone vb-script would be the simplest (without using a web page) but
using a web-page would give you more control and if you used something like
asp, then no-one could see/amend the script. However, there are two
hurdles: Firstly, you need to have a machine running IIS, and you should try
to publish an initial test page first. Once you have that working you can
create the script to add the record, but you need to let us know something
about the table structure for the record to be added. For example, database
has a single table tblContacts with two fields, ConID is an autonumber field
which serves as the primary key and ConName is the contact's name which is
input by the user. With that sort of info, someone could write the script.
Nov 13 '05 #5
"Eric Schittlipz" <er**@schittlipz.com> wrote in message news:<co**********@hercules.btinternet.com>...
"Pete" <so**********@netzero.net> wrote in message
news:8f**************************@posting.google.c om...
Yes it would be a network backend .mdb database. That's exactly the
syntax I'm looking for but I need to embed this in a simple .html file
with a textbox and button so that users can insert the record to the
mdb via the vbscript. Would you happen to have the syntax to activate
this from a web page? Any method will do (vbscript asp ...) Thanks

If you need only a single textbox, to get data from the user, then using a
stand-alone vb-script would be the simplest (without using a web page) but
using a web-page would give you more control and if you used something like
asp, then no-one could see/amend the script. However, there are two
hurdles: Firstly, you need to have a machine running IIS, and you should try
to publish an initial test page first. Once you have that working you can
create the script to add the record, but you need to let us know something
about the table structure for the record to be added. For example, database
has a single table tblContacts with two fields, ConID is an autonumber field
which serves as the primary key and ConName is the contact's name which is
input by the user. With that sort of info, someone could write the script.

You could try a simple html application. You would probably want to
add some more robust data validation. It doesn't require a server.
Only IE 5 and above and vbScript.

http://msdn.microsoft.com/workshop/a...taoverview.asp

The example below is very basic but should give you an idea of what it
does.

<html>
<head>
<title>
Data Add Form
</title>
<script language="vbscript">
sub cmdAdd_onClick
dim dbEng
dim wrksp
dim db

if VerifyData()=true then

set dbEng = createobject("dao.dbengine.36")
dbEng.systemdb = "pathtoworkgroupfile"
dbEng.defaultuser = "username"
dbEng.defaultpassword = "password"

set wrksp = dbEng.workspaces(0)

set db = wrksp.opendatabase("PathToDataBase",false,false)

db.execute "INSERT INTO tblData(DataField) " _
& "VALUES('" & txtData.value & "');",128

msgbox "Data Added"

txtData.value = ""

db.close
set db = nothing
wrksp.close
set wrksp = nothing
set dbEng = nothing

else

msgbox "Hey enter Data"
txtData.value=""

end if

end sub

function VerifyData()

if len(trim(txtData.value))=7 then

if isnumeric(txtData.value) then

VerifyData=true

else

VerifyData=false

end if

else

VerifyData=false

end if

end function

</script>
</head>
<body>
<fieldset>
<legend>Enter data to add</legend>
<center>
<input type="text" size="7" maxlength="7" name="txtData"></br>
</p>
<input type="button" name="cmdAdd" value="Add">
</center>
</fieldset>
</br>
</body>
</html>
Nov 13 '05 #6
"Dan Morgan" <us****@yahoo.com> wrote in message
news:fe**************************@posting.google.c om...
"Eric Schittlipz" <er**@schittlipz.com> wrote in message
news:<co**********@hercules.btinternet.com>...
"Pete" <so**********@netzero.net> wrote in message
news:8f**************************@posting.google.c om...
> Yes it would be a network backend .mdb database. That's exactly the
> syntax I'm looking for but I need to embed this in a simple .html file
> with a textbox and button so that users can insert the record to the
> mdb via the vbscript. Would you happen to have the syntax to activate
> this from a web page? Any method will do (vbscript asp ...) Thanks

If you need only a single textbox, to get data from the user, then using
a
stand-alone vb-script would be the simplest (without using a web page)
but
using a web-page would give you more control and if you used something
like
asp, then no-one could see/amend the script. However, there are two
hurdles: Firstly, you need to have a machine running IIS, and you should
try
to publish an initial test page first. Once you have that working you
can
create the script to add the record, but you need to let us know
something
about the table structure for the record to be added. For example,
database
has a single table tblContacts with two fields, ConID is an autonumber
field
which serves as the primary key and ConName is the contact's name which
is
input by the user. With that sort of info, someone could write the
script.

You could try a simple html application. You would probably want to
add some more robust data validation. It doesn't require a server.
Only IE 5 and above and vbScript.

http://msdn.microsoft.com/workshop/a...taoverview.asp

The example below is very basic but should give you an idea of what it
does.

<html>
<head>
<title>
Data Add Form
</title>
<script language="vbscript">
sub cmdAdd_onClick
dim dbEng
dim wrksp
dim db

if VerifyData()=true then

set dbEng = createobject("dao.dbengine.36")
dbEng.systemdb = "pathtoworkgroupfile"
dbEng.defaultuser = "username"
dbEng.defaultpassword = "password"

set wrksp = dbEng.workspaces(0)

set db = wrksp.opendatabase("PathToDataBase",false,false)

db.execute "INSERT INTO tblData(DataField) " _
& "VALUES('" & txtData.value & "');",128

msgbox "Data Added"

txtData.value = ""

db.close
set db = nothing
wrksp.close
set wrksp = nothing
set dbEng = nothing

else

msgbox "Hey enter Data"
txtData.value=""

end if

end sub

function VerifyData()

if len(trim(txtData.value))=7 then

if isnumeric(txtData.value) then

VerifyData=true

else

VerifyData=false

end if

else

VerifyData=false

end if

end function

</script>
</head>
<body>
<fieldset>
<legend>Enter data to add</legend>
<center>
<input type="text" size="7" maxlength="7" name="txtData"></br>
</p>
<input type="button" name="cmdAdd" value="Add">
</center>
</fieldset>
</br>
</body>
</html>


Agreed this has some advantages over a simple vbs file, especially when
there needs to be some form of user interface. I did write a quick one for
someone who needed to do some data manipulation with word tables but didn't
have Access. However, I haven't ever sold an hta application. The idea
never seemed to take off and you don't really see many around.

Nov 13 '05 #7
You answered my question. A statement that I know is unfortunately
true: new records cannot be added from a web page without having IIS
or some other type of web server on the client or server side. Simply
put you can not post any web page on your company's network and expect
it to interact with your database without having administrative access
and IIS. The whole reason behind this is to develop a method for
inserting records without having Access installed on the client's Pc.
I suppose one crude solution is to build a connection from excel since
most client pc have excel installed. The other solution I thought of
is to develop a simple 32bit vb .exe file with a standard input form
and copy that app if they didn't have access installed. If anyone
else has got a easier solution please let me know.
Nov 13 '05 #8

"Pete" <so**********@netzero.net> wrote in message
news:8f**************************@posting.google.c om...
You answered my question. A statement that I know is unfortunately
true: new records cannot be added from a web page without having IIS
or some other type of web server on the client or server side. Simply
put you can not post any web page on your company's network and expect
it to interact with your database without having administrative access
and IIS. The whole reason behind this is to develop a method for
inserting records without having Access installed on the client's Pc.
I suppose one crude solution is to build a connection from excel since
most client pc have excel installed. The other solution I thought of
is to develop a simple 32bit vb .exe file with a standard input form
and copy that app if they didn't have access installed. If anyone
else has got a easier solution please let me know.

IIS would be needed for ASP, but it's not the only possibility if you need
web pages. Did you see Dan's suggestion? Just amend the code slightly with
your own database details, and save this plain text file with a .hta
extension. Otherwise creating an exe file with something like Visual Basic
would be good. Another solution would be to create a runtime installation
using the Developer's version of Access, but that would probably be too much
for a simple application.
Nov 13 '05 #9
Yep. I thought there was something like this out there. After
searching and searching I was ready to give up until I saw the post
from Dan about the HTA solution. Wow this is exactly what I was
looking for. A simple solution that I actually got to work. Now I'll
have to test it when I go back to work Monday. I am pretty confident
that it will work. Thanks for the help!
http://msdn.microsoft.com/workshop/a...taoverview.asp

The example below is very basic but should give you an idea of what it
does.
if VerifyData()=true then

set dbEng = createobject("dao.dbengine.36")
dbEng.systemdb = "pathtoworkgroupfile"
dbEng.defaultuser = "username"
dbEng.defaultpassword = "password"

set wrksp = dbEng.workspaces(0)

set db = wrksp.opendatabase("PathToDataBase",false,false)

Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Samantha Smit | last post by:
Hi, I am trying to create a simple asp page that has one command button that updates a database. The URL of the page is like this: http://MyServer.com/Update.asp?UserName=Tom My asp code is...
3
by: Asif Rahman | last post by:
Hi all! Please improve on the following code to make sure the record gets deleted only when the function returns false. Now I see the msgbox, but the record gets deleted no matter the user...
1
by: Anna Warloe | last post by:
This might be a dumb question, but I am pretty new to Access.... I am trying to write code in Access to take river forecasts which are delivered as attachments in emails and append the data into...
1
by: oasd | last post by:
I'm having difficulty appending data. I have an import macro (using the Transferspreadsheet function) to import data from an excel spreadsheet (located in a USB attached to the pc) to an access...
3
by: MLH | last post by:
I have a query, qryAppend30DayOld260ies that attempts to append records to tblCorrespondence. When run, it can result in any of the following: appending no records, appending 1 record or appending...
27
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res =...
2
by: JNariss | last post by:
I keep getting the following error message when trying to preview my page: Microsoft VBScript compilation error '800a0400' Expected statement /TESTESC.asp, line 33
0
by: HydroPnik | last post by:
Hi all! What a great community you have here. Being an Access newbie I have already used much information gleaned from the other posters for my current project. I have been tasked with creating a...
1
by: anniefs | last post by:
hi help me i m so much stuck int he code and i have no time .... i used ASP VBscipt and javascript functions with MS database javascript function add records in MS DB by using ASP vbscript...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.