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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a modul using VBA

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
Anyone can help me figuring out what this modul is all about? (( Case "Ausgabe_Projekt"))I´m new to this VBA.I don´t understand -->> Set rs2 = db.OpenRecordset("Auswahl_mehrere_Projekte", dbOpenTable)....what does it mean by dbOpentable? Is it refering to a table that´s already exist?

And also-->> 'new Report: Set rep(n) = New Report_Ausgabe_Projekt.....what is it by this command?

theoritically this modul is a choice what will happen according to the case. By Case "Ausgabe_Projekt" a report should be displyed. It is also possible if a user choose to view another report after ther first is displayed.And so on. It should also be possible to print all the report,the first,the second,the third..and so on...each report consists of several pages.But this modul doesn´t function.It will only print the first report. Can anyone help me?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub auswahl_Click()
Dim rep() As Report
Dim countt As Long

Select Case OpenArgs
Case "Eingabe", "Import"
.....
.....
...
Case "Ausgabe_Projekt"

Set rs2 = db.OpenRecordset("Auswahl_mehrere_Projekte", dbOpenTable)

countt = rs2.RecordCount
ReDim rep(1 To countt)
n = 1
Do
If rs.RecordCount = 0 Then
rs.AddNew
Else
rs.MoveFirst
rs.Edit
End If
'make a copy:
rs![project_unit_name] = rs2![project_unit_name]
rs![pgid] = rs2![pgid]
rs![pgdeep] = rs2![pgdeep]
rs![pid] = rs2![pid]
rs![pdeep] = rs2![pdeep]
rs![uid] = rs2![uid]
rs.Update

'new Report:
Set rep(n) = New Report_Ausgabe_Projekt
rep(n).Visible = True

rs2.MoveNext
n = n + 1
Loop Until (n > countt) Or (rs2.EOF = True)

rs2.Close
rs.Close

db.Close
DoCmd.Close acForm, "Auswahl_Projekt", acSaveNo

DoCmd.RunCommand acCmdTileVertically

Case “Bla bla bla”

......
......
......

End Select
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Hmmm.... I tested some of the stuff here. Most of it works so I am thinking that there is a logic error somewhere that is now listed here.

As far as what this piece of code is doing it is not to hard:

Set up an array to hold reports and a counter for the reports:
Dim rep() As Report
Dim countt As Long

Test to see what type of report you are doing:
Select Case OpenArgs

If the report is this type:
Case "Ausgabe_Projekt"

Open up an input table or query:
Set rs2 = db.OpenRecordset("Auswahl_mehrere_Projekte", dbOpenTable)

redim your array to the number of records in the rs2:
countt = rs2.RecordCount
ReDim rep(1 To countt)
Incidentally, this is most likely where your problem is. Try putting this line before the two I just listed:
rs2.movelast
And then this line after the two I just listed:
rs2.movefirst

rs2.recordcount will always return 0 if there are no records or 1 if there are 1 or more records until you move to the end of the recordset. Then recordcount is accurate.

This next bunch of code is just setting up the data for the report:
If rs.RecordCount = 0 Then
rs.AddNew
Else
rs.MoveFirst
rs.Edit
End If
'make a copy:
rs![project_unit_name] = rs2![project_unit_name]
rs![pgid] = rs2![pgid]
rs![pgdeep] = rs2![pgdeep]
rs![pid] = rs2![pid]
rs![pdeep] = rs2![pdeep]
rs![uid] = rs2![uid]
rs.Update

The rest of the routine will just create the reports and make them visible. This routine should work fine after you make the change that I just suggested. One thing for future reference, when you want to do that much stuff in a case statement it is less confusing to move the code to a separate procedure and just call the procedure in the case statement.


 
Thank you allanon for the explanation.
I've tried it and still doesn't work.
How will it possible to connect to the
print icon on the control panel using procedures?
May be by the way I can print all visible project 1,project 2 ,project 3
and so on by using loops..each
consisting many pages.One loop for number of project and the other loop for the number of the page for each project.
 
When you say that it does not work what is it doing or not doing?
 
It´s still doing the same thing. Printing only one project report, leaving behind the other project reports that are visible. When I try printing the left behind reports,the access database just vanish from the screen, and I have to start thing all over again.

When I open one project at a time and print it out, it doesn´t cause any problems. BUt when I open several projects at a time, and trying to print them, only the project on the active window will be printed out.
 
Can you send this file to me. I will look at it and try to figure it out. You are right about the printing problem. Even with the little test I wrote here when I have multiple report windows open and I try to print one then BOOM then goes my access. Not really the results someone would want. If you can send your db to me I will look at what it is doing and see if there is a way around this.

Before you send it to me let me know how big it is zipped up.
 
It's been a long while since I read the book, but did you get the handle 'allanon' from the 'Elfstones of Shanara' series?

If not, sorry to bother.


Onwards,

Q-
 
You bet. Been a long time since I read the books as well but I have been using the handle ever since.
 
Hallo allanon,I´d like to send you this file,but how? Can you give me you e_mail address?
 
Send the file to

jdyck@wcb.mb.ca

I will take a look as soon as I can. Also, what version of access. I tried with Access97 and started to get some errors.
 
dear allanon..
have you received the file that i sent you 2 days ago?
 
I did not recieve the file. Hmmm, try sending it to:

jwdconsulting@shaw.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top