Solved

Getting in a muddle on Ifs

Posted on 2013-01-24
3
161 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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.

929 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