?
Solved

Getting in a muddle on Ifs

Posted on 2013-01-24
3
Medium Priority
?
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

765 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