How do you filter out blank fields?

fkneg1

Registered User.
Local time
Today, 12:50
Joined
Aug 11, 2013
Messages
23
I am making a database which has its output in PowerPoint. I have set it up so that each field value is shown on a different slide with the code for each slide like this:
Code:
 With .Slides.Add(rs.AbsolutePosition + 1, ppLayoutLargeObject)
                        .FollowMasterBackground = False
                        .Background.Fill.Solid
                        .Background.Fill.ForeColor.RGB = RGB(0, 0, 0)
                            With .Shapes(1).TextFrame.TextRange
                                 .Text = CStr(rs.Fields("Song 1 chosen_Verse 2").Value)
                                 .Characters.Font.Color.RGB = RGB(255, 255, 255)
                                 .Characters.Font.Size = 36
                                 .ParagraphFormat.Bullet = False
                                 .ParagraphFormat.Alignment = ppAlignCenter
                            End With
                        End With

This works fine until a filed is blank (which they sometimes are) where it then crashes with error 94 invalid use of null. What I was thinking was putting the whole thing above in an If-then-else statement so that a blank field does not produce a slide, something like:

Code:
If IsNull(CStr(rs.Fields("Song 1 chosen_Verse 2").Value)) Then
                    Else
                        With .Slides.Add(rs.AbsolutePosition + 1, ppLayoutLargeObject)
                        .FollowMasterBackground = False
                        .Background.Fill.Solid
                        .Background.Fill.ForeColor.RGB = RGB(0, 0, 0)
                            With .Shapes(1).TextFrame.TextRange
                                 .Text = CStr(rs.Fields("Song 1 chosen_Verse 2").Value)
                                 .Characters.Font.Color.RGB = RGB(255, 255, 255)
                                 .Characters.Font.Size = 36
                                 .ParagraphFormat.Bullet = False
                                 .ParagraphFormat.Alignment = ppAlignCenter
                            End With
                        End With
                    End If

This doesn't work though - at least not like I have written it! Any suggestions?
 
"doesn't work" conveys 0 debugging information.

Always
1. State what you want (check)
2. What do you do with what code (check)
3. What does the code do (errormessage? nothoing happens?output right/wrong)
4. If error - what error TEXT and what line failed
 
It says error 94 invalid use of null again - the debug part doesn't seem to always work so i'm not entirely sure which part is not working but all i have added is the if-the-else
 
You did not stipulate which line failed, despite my explicit request, but I'll let you off the hook this once, just because it is pretty evident The function Cstr does not accept a Null, which is what the error says. SImply remove the call to Cstr
 
I did say the debug thing doesn't seem to be working so doesn't tell me which line failed (unless I'm using that wrong too)!
Thanks though - that seems to be working fine now. :)
 
IsNull does not detect zero length strings.

Use
If Len(CStr(rs.Fields("Song 1 chosen_Verse 2"))) >0 Then
(your code ie no need for Else)
Endif


This of course does not trap an invalid entry in the record.

To debug, highlight the If statement in your code and press F9 (function key 9) to insert a breakpoint and when the code stops on this line, successive presses of F8 will show you on which line the error occurs.
 

Users who are viewing this thread

Back
Top Bottom