Generating Static Pages To Post To The Web ?This method is worth knowing as
it allows you to make the leap to a more dynamic web site without investing in backend
server technologies such as Active Server Pages
Local
Database
Software generates web pages locally
Publish pages to the web
This
solution is suited to a web site whose online content does not changed very often and one
that does not require user queries of the database. It will generally produce
a hierarchy of html pages and can be made more versatile by adding a search solution to the site. Will allow far
more freedom in the generation of the web pages. This means you can use cheaper and
simpler web hosting facilities and feature your html pages in the giant keyword engines
such as Altavista
Posting Pages To The
Web
First of all
you need to design the output that you want to achieve in a HTML editor such as FrontPage.
Keep the layout clean and consistent with the kind of output that you would expect from a
simple access report. Once the page layout has been approved by your users, you then can
import the form as HTML code into an Access module and make the HTML using print commands.
It is quite important to get quite close to the final design as this sort of
software is hard to change once in place.
For this example, we
are going to build a series of HTML pages that display the product code, the picture and
the description of the product. The first step is to loop through the records that
you want to make individual HTML pages for.
 |
The code
for this exercisecan be found in the form "FX_MakeHtml" in the demo database. |
Now run the
application and produce a few simple forms using Visual Basic Code as follows.
Set mydb = CurrentDb
que = "SELECT CategoryName, Description FROM Categories;"
Set catRst = mydb.OpenRecordset(que)
catRst.MoveFirst
Do Until catRst.EOF
DoCmd.Echo True, catRst!CategoryName
& catRst!Description
' Output the new html file
Call makeHtmlPage(catRst!CategoryName,
catRst!Description)
catRst.MoveNext
Loop
catRst.Close
The meat of this solution is the
MakeHtmlPage subroutine. At this stage it is critical to have decided the layout of the
HTML because if you have to start altering the VB code that makes the page, it is going to
waste a lot of your time. To export the HTML use the VB utilities that allow you to open
and make text files. The Access statements that I use are Open, Print, Close and FreeFile.
If you are unaware of FreeFile, this function returns the next available integer number
that can be used by the Open statement. I call the HTML files by their actually product
name as this is a unique index.
exportdir = "c:\My
Documents\"
fNum = FreeFile
fName = exportdir & LCase(productStr) & ".htm"
Open fName For Output As #fNum
Now you need to write the HTML
using the Print command. At this stage you will cut and paste your HTML into the module.
Before you get carried away and start embedding the record set variables into the print
statements, make sure that the HTML is working. The HTML language uses quotes in great
abundance so it is time to start deploying the double double quotes or the single and
double quote combinations to export what HTML wants to see. If you are unsure on this
area, Open Access help and type Quotes. Look for Quotation Marks in Strings help. As an
example, the HTML command for a background color of white is BGCOLOR="#ffffff"
and in the Print statement you need to write BGCOLOR=""#ffffff"".
Print #fNum, "<html>"
Print #fNum, "<head>"
Print #fNum, "<title>" & productStr & "
</title>"
Print #fNum, "</head>"
Print #fNum, "<body
BGCOLOR=""#ffffff""><p> </p>"
Print #fNum, "<p
align=""center""><strong>" & productStr & _
"</strong><br>"
Print #fNum, "<p
align=""center""><img src=""images/" & _
productStr & ".gif"" alt=""Product Picture""
</p>"
Print #fNum, "<p
align=""center"">" & _
DescriptionStr & "</p>"
Print #fNum, "
</body></html>"
Close fNum
To embed your recordset information
into the HTML, remove the test text that came with your initial HTML page and replace it
with your recordset variables ( ProductStr and DescriptionStr ). For this example, the
external image file is defined in the HTML by <img src=> is located in the /images
directory and stored using the same name as the unique product name. So thats how
you can generate multiple HTML files from your database. You will probably need to
generate a page that provides links to these separate pages in the function that loops
through the recordset.
Background Material:
Automating The Process Still Further
Posting these files to the internet
automatically can probably be undertaken in a number of ways but the technique that I have
devised will work on Windows 95 and uses a DOS for Windows 95 utilities called FTP
(surprise surprise). So open your DOS window from within Windows and type FTP. You may
then want to type Help to get a list of the commands. The idea here is to build the FTP
script file using the Access Print statement and then to run the script using a DOS batch
command or an Access shell command. Following is the FTP script that you could generate to
post the files to the Web.
open
yourFTP_Username
yourPassword
cd public_html
dir
put c:\my documents\beverages.htm
put c:\my documents\condiments.html
quit
To automate the process, you
need to run a shell command as a macro or as a VB script as follows
Call Shell("ftp -s:c:\my
documents\products.ftp", 1)
Next
Lesson
Published 1999-05