Solved

Getting in a muddle on Ifs

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

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…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
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…

810 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