943,493 Members | Top Members by Rank

Ad:
Apr 10th, 2003
0

Vb report generation

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
johnbal is offline Offline
2 posts
since Apr 2003
Oct 31st, 2006
0

Re: Vb report generation

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
udaywali is offline Offline
14 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Sqlserver 2005 Express Edition
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Wasnt sure where to put this





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC