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

creating textboxes using code in a report 2

Status
Not open for further replies.

VRach02

Technical User
Oct 30, 2003
35
CA

IS there a code that wil allow me to create textboxes in a report in the onformat section??

so that i don't actually have to have the textbox created but so i can create them when the report opens.

Thanks


 
Hi!

Never used it myself, but check the helpfiles on CreateControl and CreateReportControl methods, nice examples.

Roy-Vidar
 
Hello
I am using the textboxes to show the data from the tables.
Is there a better way, so something i don't know?

 
The short answer is no. Events are only triggered in the 'Normal View', but controls cna only be created in the 'Design View".



MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
You can use Me.Print to print text anywhere you want on the report. You don't need any controls and you don't have to be in design view like you would need to CreateReportControl().

For instance, to draw a complete month calendar of the current month on a page, use this code in the On Page event of the report. Make sure the report width is at least 7" wide.
[blue]
Code:
Private Sub Report_Page()
    Dim lngDayHeight As Long
    Dim lngDayWidth As Long
    Dim datRptDate As Date
    Dim intStartWeek As Integer
    Dim lngTopMargin As Long
    Dim dat1stMth As Date
    Dim datDay As Date
    Dim lngTop As Long
    Dim lngLeft As Long
    datRptDate = Date
    dat1stMth = DateSerial(Year(datRptDate), Month(datRptDate), 1)
    intStartWeek = DatePart("ww", dat1stMth)
    lngDayHeight = 2160  'one & half inch
    lngDayWidth = 1440  'one inch
    lngTopMargin = 720  'half inch
    Me.FontSize = 22
    'loop through all days in month
    For datDay = dat1stMth To DateAdd("m", 1, dat1stMth) - 1
        'find the top and left corner
        lngTop = (DatePart("ww", datDay) - intStartWeek) * _
            lngDayHeight + lngTopMargin
        lngLeft = (Weekday(datDay) - 1) * lngDayWidth
        If Weekday(datDay) = 1 Or Weekday(datDay) = 7 Then
            Me.DrawWidth = 8
         Else
            Me.DrawWidth = 1
        End If
        'draw a rectangle for day
        Me.Line (lngLeft, lngTop)-Step _
                (lngDayWidth, lngDayHeight), , B
        Me.CurrentX = lngLeft + 50
        Me.CurrentY = lngTop + 50
        Me.Print Day(datDay)
    Next
End Sub
[/blue]

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
dhookom!

Wow!!!! Learn't a lot by watching your replies, but this is simply great! Long overdue star from me!

VRach02!
Sorry I overlooked the in the onformat part.

Roy-Vidar
 
Glad you liked this. I had written similar code once that drew a US flag etc. Access reports are amazing. For some other graphics and text samples, check out Corp Tech Demos and the Calendar Reports at
Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
hey

Thanks guys for all the help. The code looks alittle bit daunting but i'll work through it and adjust to meet my needs. This method also works to take data from a SQL command or table?

And i can format the text and background when i set it up ?
 
You can use ADO or DAO to get data from almost any data source to print in the report. Keep in mind that reports don't have a recordset property like forms.

You can format the font. In the code, if you type
Me.
you will see lots of properties that are exposed such as FontSize, ForeColor, FontName, etc.

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Thanks for the help.
I've been side tracked on another project, but will update on how ths code work for me next week.

Thanks
Vishal
 
" ... reports don't have a recordset property ..."??


isn't is "RecordSource" in BOTH? The only recordset of a form I am aware of is the recordset clone.



MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Michael,
This depends on your version of Access. Forms now have a Recordset property in addition to a record source property. In all my work, I have never set the Recordset property of a form. I have used the recordset clone in the past.

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top