FersonS
Oct 26 2006, 03:43 PM
I'm creating a report where if certain conditions are true, I want certain messages to be included as a line in the report. The following code is working fine, except that I cannot figure out formatting. It comes out where each message starts on the next line which is good. But it also starts at the END of the message above it, giving it a staircase kind of look. How do I tell each message to start justified all the way to the left. In other words, how do I line them up?
Private Sub Detail_Format(Cancel As Integer, _
PrintCount As Integer)
Dim rpt As Report
Dim strMessage1 As String
Dim strMessage2 As String
Dim strMessage3 As String
Set rpt = Me
If Me.INMDS = 0 Then strMessage1 = "DisplayMessage for 0"
If Me.INMDS = 1 Then strMessage1 = "DisplayMessage for 1"
If Me.REASON = 2 Then strMessage2 = "DisplayMessage for REASON = 2"
If Me.REFER = 2 Then strMessage3 = "DisplayMessage for REFER = 2"
' Print text on Report object.
rpt.Print strMessage1
rpt.Print strMessage2
rpt.Print strMessage3
End Sub
freakazeud
Oct 26 2006, 08:37 PM
Hi,
your If statements are missing End If blocks...furthermore I would add a textbox control to the report and set its value according to your evaluation rather then what you are doing right now...this way it will always be in the same place e.g.:
If Me.INMDS = 0 Then
Me.YourOtherControl = "DisplayMessage for 0"
ElseIf Me.INMDS = 1 Then
Me.YourOtherControl = "DisplayMessage for 1"
End If
If Me.REASON = 2 Then
Me.YourOtherControl = "DisplayMessage for REASON = 2"
...
HTH
Good luck
FersonS
Oct 27 2006, 09:22 AM
Thank you for your input.
I've never used "End if" when the If statement only triggers one event. It's a single event, not a block of events, so it doesn't seem necessary. To me it just seems like extra code that adds unnecessary clutter.
I have thought about the textbox method and may have to go with that. However, I have a long list of possible messages, so I'd prefer they not always be in the same place. I'd prefer that whatever messages are triggered come one after another, not one and then a bunch of blank lines and then another one. And I realize I could (and might) just set the textboxes to Can Grow, but that makes them much more difficult to view in design mode.
I'm having a hard time believing there is no way to use the strMessages for this, so I'm going to keep playing.
Thanks!
-S
freakazeud
Oct 27 2006, 09:27 AM
Hi,
yes...I would use the can grow/shrink properties of controls then...!
An if then else statement also needs an End If.
HTH
Good luck
FersonS
Oct 27 2006, 10:16 AM
I don't remember ever using !
What does that do?
If anyone cares how I did solve this, this is my code now:
Private Sub Detail_Format(Cancel As Integer, _
PrintCount As Integer)
Dim rpt As Report
Dim strMessage1 As String
Dim strMessage2 As String
Dim strMessage3 As String
Set rpt = Me
If Me.INMDS = 0 Then
strMessage1 = "DisplayMessage for 0"
rpt.Print strMessage1 & vbCrLf
End If
If Me.INMDS = 1 Then
strMessage1 = "DisplayMessage for 1"
rpt.Print strMessage1 & vbCrLf
End If
If Me.REASON = 1 Then
strMessage2 = "DisplayMessage for REASON = 1"
rpt.Print strMessage2 & vbCrLf
End If
If Me.REFER = 2 Then
strMessage3 = "DisplayMessage for REFER = 2"
rpt.Print strMessage3 & vbCrLf
End If
End Sub
So now I am telling it, if (and only if) this condition is met, print the message and add go to the beginning of a line. My code isn't entirely complete, but for the purpose of the question I was asking, it is. Seems to be working ok so far, but we'll see.
freakazeud
Oct 27 2006, 10:19 AM
Glad you got it sorted out.
Good luck on future projects!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.