Solved

Getting in a muddle on Ifs

Posted on 2013-01-24
3
159 Views
Last Modified: 2013-01-24
Dear Experts,

I have a piece of code where I am getting in a mess on the If statements, I have played around with it to such an extent I cant think straight on it -

The code is below, what it should do is this ... if the string "MissingFields" has something in it then a warning box pops up to ask the user if they want to carry on (Yes / No). If yes then it carries on.

At present if there is data in the string "MissingFields" then it works all ok, but if it is an empty string then then the code stops

' Warning box if data is missing
If MissingFields <> "" Then
If MsgBox("You are missing the following fields:" & vbCr & vbCr & MissingFields & vbCr & vbCr & "Do you wish to Continue", vbYesNo, "Warning !") = vbYes Then
End If

' Output File
Dim OutputFile As String

OutputFile = Application.CurrentProject.Path & Me.[Fold-StartDocs] & "\Individual Starter Form - IT.pdf"
 MsgBox (OutputFile)
 
 DoCmd.OutputTo acOutputReport, "Individual Starter Form - IT", "PDFFormat(*.pdf)", OutputFile, False, "", 0, acExportQualityPrint

'Email File
Dim MsgContent As String
Dim StartBit4EmailMessage As String

If Nz(Me.[Start-Startdate], "") = "" Then
StartBit4EmailMessage = " who is starting with us shortly"
Else
StartBit4EmailMessage = " who is starting with us on " & Me.[Start-Startdate]
End If
Dim SenderName As String


MsgContent = "Hi" & vbCr & vbCr & "Please find attached a starter form for " & StartBit4EmailMessage & vbCr & vbCr & "Best Regards" & vbCr & vbCr
DoCmd.SendObject acReport, "Individual Starter Form - IT", "PDFFormat(*.pdf)", "", "", "", "Arcus New Starter - " & Me.[Gen-FullName], MsgContent, True, ""

End If

End Sub

Open in new window


If anyone could save me from further brain ache that would be most appreciated
0
Comment
Question by:correlate
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38813999
See if this does what you need:

' Warning box if data is missing
If trim("" & MissingFields ) <> "" Then
      If MsgBox("You are missing the following fields:" & vbCr & vbCr & MissingFields & vbCr & vbCr & "Do you wish to Continue", vbYesNo, "Warning !") <> vbYes Then
       exit sub
      end if
    
End If

' Output File
Dim OutputFile As String

OutputFile = Application.CurrentProject.Path & Me.[Fold-StartDocs] & "\Individual Starter Form - IT.pdf"
 MsgBox (OutputFile)
 
 DoCmd.OutputTo acOutputReport, "Individual Starter Form - IT", "PDFFormat(*.pdf)", OutputFile, False, "", 0, acExportQualityPrint

'Email File
Dim MsgContent As String
Dim StartBit4EmailMessage As String

If Nz(Me.[Start-Startdate], "") = "" Then
       StartBit4EmailMessage = " who is starting with us shortly"
Else
         StartBit4EmailMessage = " who is starting with us on " & Me.[Start-Startdate]
End If

Dim SenderName As String


MsgContent = "Hi" & vbCr & vbCr & "Please find attached a starter form for " & StartBit4EmailMessage & vbCr & vbCr & "Best Regards" & vbCr & vbCr
DoCmd.SendObject acReport, "Individual Starter Form - IT", "PDFFormat(*.pdf)", "", "", "", "Arcus New Starter - " & Me.[Gen-FullName], MsgContent, True, ""



End Sub

Open in new window

0
 

Author Closing Comment

by:correlate
ID: 38814013
Perfect - Thank you very much, it was doing my head in trying to get this going
0
 
LVL 77

Expert Comment

by:peter57r
ID: 38814027
The problem are ais this command...

If MsgBox("You are missing the following fields:" & vbCr & vbCr
& MissingFields & vbCr & vbCr & "Do you wish to Continue", vbYesNo, "Warning !") = vbYes Then
    End If


It doesn't matter what the user answers to this question , the code continues in exactly the same way.

Assuming you want to end the process if the users says no you need..


If MsgBox("You are missing the following fields:" & vbCr & vbCr & MissingFields & vbCr & vbCr & "Do you wish to Continue", vbYesNo, "Warning !") = vbYes Then
'do nothing
else ' No
exit sub
 End If
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now