473,388 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

pls help me guys! I need help regarding report generation with VBA coding

I need to create an access report uisng VBA code. i want to be able to create a report name and save it and also create labels and text boxes in the report using the vba code and those fields should come from the table in the database. and data of the table should be displayed in the report under each field in the report as well.

im new to access and vba. and i want to get this job done quickly.someone please please help me on this and it would be really greatfull. i hope there'll be someone to help me........
Apr 10 '07 #1
4 1703
pks00
280 Expert 100+
Why do u want to use vba code to do this? Why cant u just design a report using report wizard or something to help you?
Apr 10 '07 #2
well my requirement is to generate customizable reports using cross tab query. i've already developed a form having four combo boxes. two of them filled with two tables data and other two filled with field names of tables. so when a user selects these items from the combo boxes then selected items go as parameters to a Cross tab query and created a recordset from that. i've created a temporary table and insert data into that table using that Recordset(Cross tab query). now i want to create a report from that table. i have a code taken from the Internet that would create a report using vba code. but i've tried it but it gives an error saying that "u must be in design view to create controls". so im stuck at this moment.

so i need some help to create the report using vba code or else can i pushed the records in that table to an Excel sheet and create the report...? if it is possible someone pls help me out......!
Apr 11 '07 #3
pks00
280 Expert 100+
Here is sample code that creates a new report and adds one label and textbox
Its a start. Given a report opened in design view, u should be able to set the recordsource and do other things


Expand|Select|Wrap|Line Numbers
  1.     Dim rpt As Report
  2.     Dim sRptName As String
  3.  
  4.  
  5.     'Create new report
  6.     Set rpt = CreateReport()
  7.  
  8.     'Store the automatically generated name
  9.     sRptName = rpt.Name
  10.  
  11.     'Open report in design mode
  12.     DoCmd.OpenReport sRptName, acDesign
  13.  
  14.     'Create controls
  15.     CreateReportControl sRptName, acLabel, acDetail, , , 100, 100, 500, 250
  16.     CreateReportControl sRptName, acTextBox, acDetail, , , 100, 400, 500, 250
  17.  
  18.     DoCmd.Close acReport, sRptName, acSaveYes
  19.  
  20.     'Rename report to something more meaningful
  21.     DoCmd.Rename "pksTSDN", acReport, sRptName
  22.  
Apr 11 '07 #4
I used ur sample code, modified it and created a report but it shows all fields/columns in the table in rows. i want to display those fields and its related data in columnar format.so can u tell me how to display related fields and data and how do u call the record source.. the way i called it gave an error saying that " Object Variable or with block variable not set" . Here is the code i cretaed.


Expand|Select|Wrap|Line Numbers
  1. ----------------------------------------------------------
  2. Public Sub PreviewReport_Click()
  3.  
  4. createtNewReport
  5.  
  6. End Sub
  7. ----------------------------------------------------------
  8.  
  9. Public Sub createtNewReport()
  10. On Error GoTo err_createtNewReport
  11.  
  12. Dim txtNew As TextBox
  13. Dim lblNew As Label
  14. Dim rpt As Report
  15. Dim sRptName As String
  16. Dim fldData As Field
  17. Dim lngTop As Long
  18. Dim lngLeft As Long
  19.  
  20. lngTop = 0
  21. lngLeft = 0
  22.  
  23. Dim dbCurr As Database
  24. Dim rsRecordset As Recordset
  25.  
  26. 'set report's record source property
  27. 'rpt.RecordSource = "X"
  28.  
  29. Set dbCurr = DBEngine.Workspaces(0).Databases(0)
  30. Set rsRecordset = dbCurr.OpenRecordset("X")
  31.  
  32. sRptName = "Report1"
  33.  
  34. DoCmd.OpenReport sRptName, acViewDesign
  35.  
  36. For Each fldData In rsRecordset.Fields
  37.  
  38. 'create controls
  39.  
  40. Set txtNew = CreateReportControl(sRptName, acTextBox, acDetail, , fldData.Name, lngLeft + 1500, lngTop)
  41. txtNew.SizeToFit
  42.  
  43. Set lblNew = CreateReportControl(sRptName, acLabel, acDetail, txtNew.Name, fldData.Name, lngLeft, lngTop, 1400, txtNew.Height)
  44.       lblNew.SizeToFit
  45.  
  46.  
  47. 'Increment top calue for next control
  48. lngTop = lngTop + txtNew.Height + 25
  49.  
  50. Next
  51.  
  52. DoCmd.Close acReport, sRptName, acSaveYes
  53.  
  54. '------------------------------------------------
  55. exit_createtNewReport:
  56. Exit Sub
  57.  
  58. err_createtNewReport:
  59. MsgBox Err.Description
  60. Resume exit_createtNewReport
  61.  
  62. End Sub
  63.  
  64.  
Apr 19 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: echo01 | last post by:
Hey when do you guys think 5.0 will be stable or considered stable. i think the are up to 5.0.2?
2
by: sheldon279 | last post by:
Hi guys. First time poster long time reader. Just wanted to say "Hi" ;) On a side note my Hubby is REAL excited about this new IPO stock GRDX. They just started trading this one like 2 days...
0
by: inquisitiveman2002 | last post by:
You guys ever notice that many websites have forums that look like they're using the same software from the same company. For example, look at these 2 different sites, yet the same type of forum. ...
34
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
92
by: Jeffrey P via AccessMonster.com | last post by:
Our IT guys are on a vendetta against MS Access (and Lotus Notes but they've won that fight). What I can't understand is, what's the problem? Why does IT hate MS Access so much. I have tried...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.