2003.09.19 10:42 AM
Access Draws a Line
Want to programmatically draw some lines on an Access report? No problem. That's what the Access.Report.Line method is all about. Unfortunately, its documentation and interface definition are wrong. There's probably a Knowledge Base article somewhere describing this, but I haven't seen it. Here's the Line method's documentation, and here's its interface definition as described by the object browser (you'll get no Intellisense hint with this method):
Sub Line(flags As Integer, x1 As Single, y1 As Single, x2 As Single, y2 As Single, color As Long)
There's nothing in the documentation describing the first parameter, and the syntax used in the documentation's sample code makes the call like this:
rpt.Line(sngTop, sngLeft) - (sngWidth, sngHeight), lngColor, BEnd Sub
Huh?! Putting aside the "BEnd Sub" that ends the line (the "End Sub" is obviously supposed to be on the next line, but what the hell is the ", B"?), that syntax definitely does not match the signature described by the interface definition. Finally, if you try a Line method call using the described interface definition, you'll get a compilation syntax error. Go ahead and try it:
Me.Line 0, 0, 0, 0, Me.Height, 0
So, here's how it's really done. Use the following oddball syntax:
object.Line [[Step](x1, y1)] - [Step](x2, y2)[, [color][, B[F]]]
This comes from the Access 97 help. Big thanks to Stephen Lebans for posting it on Google (here's his message, which includes the doc for the above syntax). Note that Mr. Lebans posted this last November, so this has been known for some time. Yet the official MS documentation is still wrong?! Jeez.
So, how's about an example? Okay. Create a simple report and bind it to a table or query (or use one you already have), and in the detail section's Print event, place this code:
Me.Line (0, 0)-(0, Me.Height), 0 Me.Line (0, Me.Height)-(Me.Width, Me.Height), 0 Me.Line (0, 0)-(Me.Width, 0), 0 Me.Line (Me.Width, 0)-(Me.Width, Me.Height), 0
Assuming I got my X's and Y's right, you should see a 1px black border around each detail section when you preview or print the report. Because I specified absolute coordinates, not coordinates relative to the report's CurrentX/Y properties, I didn't specify the "Step" keyword.
Remember to always draw your lines in Print events, not Format events, as section sizes are subject to change between Format and Print.
I read more than once the whole text from top to bottom, I'm afraid I still don't know what the B[F] refers to in the oddball syntax object.Line [[Step](x1, y1)] - [Step](x2, y2)[, [color][, B[F]]] above.
kowalsky | 2005.02.08 03:13 PM
shoulda have read the message on the massage link !!!
kowalsky | 2005.02.08 03:16 PM
ewbi.develops | 2005.02.08 08:19 PM
The B and F following the "oddball" syntax draw the line as a box and a filled box respectively using the two points. This is a hangover from legacy methods used in previous versions of basic to ensure compatibility: the function syntax is perfectly correct. As for the drawstyle argument, it is a normal flag integer with each bit representing transparency, color style, fill and so on - consult MSDN!
Rory Allford | 2005.05.31 03:30 PM
Thankyou for this brilliant article. I was puzzled by all the strangeness you describe here. The Format vs Print tip was helpful too. Interestingly, I seem to remember using the same kind of syntax (x1,y1) - (x2,y2) when drawing lines in GWBASIC as a kid, so I guess Microsoft have just kept the syntax all the way through their products.
Adam Collings | 2010.07.28 09:51 PM
TrackBack URL: http://www.typepad.com/services/trackback/6a00d8341c7bd453ef00d834369ed153ef
Listed below are links to weblogs that reference Access Draws a Line: