Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4102038
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:46:28+00:00 2026-05-20T20:46:28+00:00

This is by no means essential, but I would like to find out how

  • 0

This is by no means essential, but I would like to find out how to create more efficient code, and i’m sure this is far from efficient!

On the form disabled fields values are cleared before the form is saved.

The below code send a message to the user to inform them that they may lose some data if they leave a checkbox unchecked.
In the context of the form it all makes sense, i would just like to know a simpler methodology, i’m sure i could use an array somewhere but cant quite figure it out.

Dim couldLoseData As Boolean
Dim msgStr As String

couldLoseData = False

If (Me.chkInvSent = False) And (Not IsNull(Me.invoicedDate)) Then
        couldLoseData = True
        msgStr = "Invoice Sent"
End If
If (Me.chkFeePaid = False) And (Not IsNull(Me.datePaid)) Then
    couldLoseData = True
    If msgStr = "" Then
    msgStr = "Claim Fee Paid"
    Else
    msgStr = msgStr & " / Claim Fee Paid"
    End If
End If
If (Me.chkFeeLodged = False) And (Not IsNull(Me.lodgedDate)) Then
    couldLoseData = True
        If msgStr = "" Then
        msgStr = "Fee Lodged"
        Else
        msgStr = msgStr & " / Fee Lodged"
        End If
End If
If couldLoseData = True Then
    If MsgBox("You will lose data in the following areas as the relevant checkboxes are unticked." & vbNewLine & vbNewLine & _
        msgStr & vbNewLine & vbNewLine & "Do you wish to continue?", vbYesNo, dbNameOf) = vbNo Then
        Cancel = True
    End If
Else
    '
'
'
'   Procedure that gets carried out here

End If

No biggie but if any one could offer me a simpler solution it would be appreciated.

Cheers

Noel

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:46:28+00:00Added an answer on May 20, 2026 at 8:46 pm

    I’m not sure why you think you should be using arrays. When it comes to the msgStr variable logic I would just put in the following:

    msgStr = msgStr & "Invoice Sent / "
    

    rather than the five lines of If msgstr = “” Then, etc, etc, End If lines.

    Then at the end I would put in the following line

    msgStr = lef(msgStr, len(msgStr) - 3) ' remove the trailing /
    

    This then removes the trailing ” / “

    Purists will tell you that you should never add anything to a string you later remove. I say, so long as you leave a comment there for the next person who is reading your code, this reduces complexity of your preceding lines of code making it much easier to grasp exactly what is going on.

    Whenever I’m looking for a value to be returned from a MsgBox I place the string creating in a separate line of code. Thus is much easier to see, at a glance, exactly what the code is doing.

    strMsg = "You will lose data in the following areas as the relevant checkboxes are unticked." & vbNewLine & vbNewLine & _
        msgStr & vbNewLine & vbNewLine & "Do you wish to continue?"
    If MsgBox(strMsg, vbYesNo, dbNameOf) <> vbYes Then _
        Cancel = True
    

    If I’m only setting one value in the If statement, such as you show, I will also put in the _ and thus not require the End If.

    I also prefer <> vbYes just in case something wonky should happen or if someone, not you of course, mucks with the msgbox options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have no idea what this means. But here is the code that it
I got this code from the wordpress <head profile=http://gmpg.org/xfn/11> What does this means? what
This may not sound like a coherient question, but I need to find some
Please have a look at the following machine code ‎0111001101110100011100100110010101110011011100110110010101100100 This means something. I
Does anyone know why this code doesn't work. This means, the alert is NOT
We have a data model that has some requirements. I would like to find
There seems to be no shortage of questions out there about this, but it's
I have a composite primary key table (Maintenance Items). I would like to create
Can someone please tell me what this means: 07-04 09:54:38.048: I/DetailActivity(15496): Title that is
If I understand it correctly this means extern void foo(); that the function foo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.