Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating HTML documents with forms / Reports 2

Status
Not open for further replies.

boardgamer

Programmer
Feb 14, 2009
58
0
0
US
How is the best way to create an HTML file for each record in the database, and save it to a unique name (which is also stored in the database)


 
You may consider the DoCmd.OutputTo method

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I think your question is best described as vague.

A database contains tables which contain records.

An HTML file is basically a text file that contains HTML code, and saved to .htm or .html format.

You don't specify whether you're only talking about doing this for existing records, and/or new records.

Also, I'm assuming you already have the HTML code that you can shoot into a new file, and possibly edit as necessary via code, to match each record?

Adding the name of each file to an already existing table should be pretty strait forward.

There are probably more than one way to do this, but in general I think it'd be easiest to accomplish using VBA.

So, if you're wanting to handle this from your form, I'll assume you want to click a button. The pseudo-code would be something like this, I suppose:
Code:
Private Sub cmdMyFancyButton_Click()
[green]'Set up your variables[/green]
  Dim db as DAO.Database
  Dim rs as DAO.Recordset
  Dim strSQL As String
  Dim strFilePath As String
  Dim strHTML1 As String
  Dim strHTML2 As String

  Set db = CurrentDb
  Set db = db.OpenRecordset("tblMyFancyTable")  

[green]'I'd probably first create the file name/location, and THEN create the files.
'Easiest way would be to just add a new column called FileName, manually,
'then procede to fill it with an Access query or some SQL code like following:[/green]
  strFilePath = "C:\MyFancyFiles\"
  strSQL = "UPDATE tblMyFancyTable " & Chr(13) & _
           "SET FileName = strFilePath & RecordID & ".html"
  DoCmd.SetWarnings False
  DoCmd.RunSQL strSQL
  DoCmd.SetWarnings True

[green]'Then loop through the table, creating your files[/green]
  Do While Not rs.EOF
[green]'Use the 2 strHTML variables (strHTML1 and strHTML2) to store the values other than your RecordID
'which you can slap between the 2, if that's the only difference.
'Then create the HTML file or text file, by specifying where it'll be saved
'and specifying the contents with your combined string of HTML..
'Of course, if you're just looking to create Access Pages to be reports of the records,
'you'll just need to create new Access Pages.
'And for that, you could probably create a template, and then create the new pages based off the template - just guessing[/green]
  Loop

  rs.Close
  Set rs = Nothing
  db.Close
  Set db = Nothing
  
End Sub

Also, you can use the above loop, or whatever type of loop you prefer, along with the DoCmd.OutPutTo method as PHV suggests if it suits your needs better.

Basically, this should give you the general idea. If you need more specific help, please be more specific with your question.

--

"If to err is human, then I must be some kind of human!" -Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top