Coding Problem

G

Guest

First I would like to thank Graham for the help with the referencing problem I had. The program now works well if anyone is interested that was the READ A FIELD in a report and copy the contents of 03/03/04. I have the code below and I am asking if someone could help me with the 2 problems I have with it now. Problem one I run the function and it stops at the level of opening the form. The form is minimized and that is it. I will then press run again and it will proceed to the rest of the code without reopening the form. I will like to run it once to the end. Problem two. It fails to create the report and it said because I do not have enough free disk space for temporal work files. Now I know I go lots of disk space. This computer has 60gb and is a 1.5mghz pentium. In other words how can I be without space and how do I get more

Option Compare Databas
Option Explici

'NAME AND SAV

'---------------------------------
Function NAMEANDSAVE() 'Name of function to name and save a report into a specified file folde
On Error GoTo NAMEANDSAVE_Er

Dim CName As String 'This string carries the name and passes it to the output comman
DoCmd.OPENFORM "visitPages", acNormal 'This opens the form with the name string made by concatinating several fields. Format as string (Firstname,Middlename,Lastname,dateofbirth
CName = Forms!VisitPages!Text351 'This is the field where the name is created. The name is not stored in a table
DoCmd.Close acForm, "VisitPages", acSaveNo 'The form is closed with the name passed
DoCmd.OutputTo acReport, "SingVispt", "SnapshotFormat", "C:\Documents and Settings\Administrator\My Documents\testfolder\" & CName & ".snp", False, "",
'In this long command the correct report is opened and the name is passed to it. It is then stored in a test folder as a snap sho
DoCmd.Close acReport, "SingVispt", acSaveNo 'The report is close
MsgBox " The Chart Name that was given was " & CName 'Informatio is given to the user about the name given to the fil
CName = "" ' Cname is returned to empty

NAMEANDSAVE_Err
MsgBox Error

End Functio

I appreciate any help in this Very much. Ideas on better doing this are also welcome
 
G

Graham R Seach

Musiwa,

If the name is not stored in a table, but is a concatenation of several
fields that are, it would seem more appropriate to open the table directly
and "calculate" the name without worrying about opening the form. For
example:

Dim Db As Database
Dim rs As DAO.Recordset
Dim CNameAs String

Set db = CurrentDb
Set rs=db.OpenRecordset("SELECT Left([FirstName], 1) & Left([LastName], 1)
As ExampleName FROM tblMyTable", dbOpenSnapshot)

CName = rs!ExampleName
rs.Close

DoCmd.OutputTo acReport, "SingVispt", "SnapshotFormat", _
"C:\Documents and Settings\Administrator\My Documents\testfolder\" &
CName & ".snp", False, "", 0
MsgBox " The Chart Name that was given was " & CName

Set rs = Nothing
Set db = Nothing

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

MUSIWA said:
First I would like to thank Graham for the help with the referencing
problem I had. The program now works well if anyone is interested that was
the READ A FIELD in a report and copy the contents of 03/03/04. I have the
code below and I am asking if someone could help me with the 2 problems I
have with it now. Problem one I run the function and it stops at the level
of opening the form. The form is minimized and that is it. I will then press
run again and it will proceed to the rest of the code without reopening the
form. I will like to run it once to the end. Problem two. It fails to
create the report and it said because I do not have enough free disk space
for temporal work files. Now I know I go lots of disk space. This computer
has 60gb and is a 1.5mghz pentium. In other words how can I be without space
and how do I get more.
Option Compare Database
Option Explicit

'NAME AND SAVE
'
'----------------------------------
Function NAMEANDSAVE() 'Name of function to name and save a report into a specified file folder
On Error GoTo NAMEANDSAVE_Err

Dim CName As String 'This string carries the name and passes it to the output command
DoCmd.OPENFORM "visitPages", acNormal 'This opens the form with the name
string made by concatinating several fields. Format as string
(Firstname,Middlename,Lastname,dateofbirth)
CName = Forms!VisitPages!Text351 'This is the field where the name is
created. The name is not stored in a table.
DoCmd.Close acForm, "VisitPages", acSaveNo 'The form is closed with the name passed.
DoCmd.OutputTo acReport, "SingVispt", "SnapshotFormat", "C:\Documents and
Settings\Administrator\My Documents\testfolder\" & CName & ".snp", False,
"", 0
'In this long command the correct report is opened and the name is passed
to it. It is then stored in a test folder as a snap shot
DoCmd.Close acReport, "SingVispt", acSaveNo 'The report is closed
MsgBox " The Chart Name that was given was " & CName 'Informatio is given
to the user about the name given to the file
CName = "" ' Cname is returned to empty.

NAMEANDSAVE_Err:
MsgBox Error$

End Function

I appreciate any help in this Very much. Ideas on better doing this are
also welcome
 
G

Guest

Thankyou Graham it works nicely. I hope you do not get tired of my ignorance but I have one more question. Is it possible to use a table made by a query instead. See the name is concatenated after the correct record is selected from the database. Also the report is built from the same query. I have a query SINGSVIPT which selects the correct record from which I make the report that is then saved. If I can reference the query I can get the Concatenated name and make the correct report too

THANK YOU VERY MUCH IN ADVANCED.
 
G

Graham R Seach

Musiwa,

Yes you can use a query to create a table, just use the SELECT INTO syntax.
For example:
SELECT * INTO tblMyNewTable FROM myTableOrQuery

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Musiwa said:
Thankyou Graham it works nicely. I hope you do not get tired of my
ignorance but I have one more question. Is it possible to use a table made
by a query instead. See the name is concatenated after the correct record is
selected from the database. Also the report is built from the same query. I
have a query SINGSVIPT which selects the correct record from which I make
the report that is then saved. If I can reference the query I can get the
Concatenated name and make the correct report too.
 

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