Vb report generation

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2003
Posts: 2
Reputation: johnbal is an unknown quantity at this point 
Solved Threads: 0
johnbal johnbal is offline Offline
Newbie Poster

Vb report generation

 
0
  #1
Apr 10th, 2003
I have a table for which I have to create a report.The user must only enter the dates(from and to).The date field is present in the table.

Please help me to do this.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 14
Reputation: udaywali is an unknown quantity at this point 
Solved Threads: 0
udaywali udaywali is offline Offline
Newbie Poster

Re: Vb report generation

 
0
  #2
Oct 31st, 2006
The first thing you want to do is select data that needs to be included in the report. So, write a small function like this:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. private function GetSQL() as string
  2.  
  3. dim sql as string
  4.  
  5. sql = "Select * from mytable"
  6. sql = sql & " Where myDate <= #" & txtFromDate & "#"
  7. sql = sql & " And myDate >= #" & txtToDate & "#"
  8.  
  9. GetSQL = sql
  10.  
  11. end function

Of course, I am assuming that user will enter date in text fields txtFromDate and txtToDate.

Next thing you want to do is to print the data on to a form. Include a picturebox on the form. Print to that picturebox.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. private sub printReport()
  3. dim rs as ADODB.Recordset
  4. dim curY as integer
  5. dim th as integer
  6.  
  7. set rs = new ADODB.recordset
  8. rs.connnection = cnn 'assuming this is opened on form load, etc.
  9.  
  10. rs.open GetSQL(), adopenstatic
  11.  
  12. picture1.cls
  13.  
  14. picture1.currentx = 1250
  15. picture1.currenty = 210
  16. picture1.fontname = "Arial"
  17. picture1.fontsize = 12
  18.  
  19. th = picture1.textHeight("junk")
  20. picture1.print "Heading for Report"
  21.  
  22. curY = 210 + th + 100 'border from header
  23.  
  24. do while not rs.eof
  25. printFld 100, curY, rs.field(0)
  26. printFld 400, curY, rs.field(1)
  27. 'so on for other fields
  28. rs.movenext
  29. curY = curY + th
  30. if curY > picture1.height then
  31. exit do
  32. loop
  33. rs.close
  34.  
  35. end sub
  36.  
  37. private sub printFld (x as integer, y as integer, s as string)
  38. picture1.currentx = x
  39. picture1.currenty = y
  40. picture1.print s; 'you may skip the semi colon
  41. end sub


I have only given the skeleton of the report generator. I have not included any error handling. I have not included page handling, report totals, etc. I assume ADO references are included in your project.

You can do the same thing with printer instead of picturebox, but with some exceptions like printer.enddoc, to send the report to printer. See VB help on enddoc, printer orientation, etc. if you wish to send it to printer.

Let me know if you need more help.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC