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 7073829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:58:37+00:00 2026-05-28T05:58:37+00:00

I have input from Form Name,Branch (text) x,y and Total are (number) fields Record

  • 0

I have input from Form Name,Branch (text) x,y and Total are (number) fields

  • Record needs to be saved when user provides all the input fields
  • Total field = sum (x + Y)

I tried the below code during testing …

Problem:

I provided the name field data but Branch was provided null and tried to save.. ( Below logic sending message “A value is required for Branch …”
when clicked on ok still logic is validating the validatenum function and sending message if total is not equal…

But I need form to stop when first validation failed itself it show branch data missing message and control should go to branch filed and other logic should not get executed..

I think I am doing something wrong with the logic .. can some help me with this simple logic…

I also given outline VB logic here.


Code:

---------
Option Compare Database
Option Explicit
Dim cancel As Boolean
---------------------------
Public sub save_click()
call validateinput
call validatenum
DoCmd.RunCommand acSaveRecord
End sub 
----------------------------
Private Sub validatenum()

If Me.Total.Value = Me.X.Value + Me.Y.Value then 

Else
MsgBox " Total s not matched with x + Y feilds"", vbRetryCancel
End If
End sub
----------------------------
Private Sub validateinput()
If Me.Name.ListIndex = -1 Then
  MsgBox "A value is required for Namefeild ..."
  Me.Name.SetFocus
    cancel = True

End If

If Me.Branch.ListIndex = -1 Then
  MsgBox "A value is required for Branch ..."
  Me.Branch.SetFocus
    cancel = True

End If
End sub
  • 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-28T05:58:37+00:00Added an answer on May 28, 2026 at 5:58 am

    Just add line with text “Exit Sub” before “End If” for each validation

    PS: Read your code once again and noticed that “cancel = True” actually does nothing, so I would rewrite it something like this:

    Option Compare Database
    Option Explicit
    ---------------------------
    Public sub save_click()
        Dim ValidateResult As String
        ValidateResult = Validate()
        If ValidateResult = "" 
            DoCmd.RunCommand acSaveRecord
        Else
            MsgBox ValidateResult
        End If
    End sub 
    ----------------------------
    Private Function Validate() As String
        Validate = ""
        If Me.Name.ListIndex = -1 Then
            Validate = "A value is required for Namefeild ..."
            Me.Name.SetFocus
        ElseIf Me.Branch.ListIndex = -1 Then
            Validate = "A value is required for Branch ..."
            Me.Branch.SetFocus
        ElseIf Me.Total.Value <> Me.X.Value + Me.Y.Value then 
            Validate = "Total s not matched with x + Y feilds"
        End If
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a form that accepts some input from a user that may
I have saved input from a textarea element to a TEXT column in MySQL.
I have problem with $_POST data. Some fields are missing from input form when
I have a login form that has Username and password as inputs from user
I have a situation where I have to take input from the user using
Quick question about CI. I have a view with a form, several text input
I have an assignment that asks me to retrieve delimited text from form values.
I have a form with Name : input and a submit. When pressed, it
If i have input text in form like this <form action=add.php method=post> <input type=text
I have an input field that is filled in from a previous form(so the

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.