Solved

Getting in a muddle on Ifs

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

828 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