473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Validate values of controls in continuous form

24
Hi,

I am struggling to find the right solution for my situation. I am still very new to Access, continuous forms and VBA, so excuse my ignorance

I have a continuous form in Access 2007. One of the controls on the form is a text box with an expected arrival date. This control can be edited by the user. I need to validate that this control is not blank before running my insert and/or update SQL queries.

Currently I am validating this in a button click event, but this only checks the first line on the form and when a value is entered on the first line, it continues with the insert/update commands.

I need to validate that all the expected arrival date values are entered before any SQL queries may execute.

Expand|Select|Wrap|Line Numbers
  1. If Me.ArrivalDate = "" Or IsNull(Me.ArrivalDate) Then
  2.         MsgBox "You have not selected an arrival date!", vbCritical + vbOKOnly, "Empty Arrival Date!"
  3.         Me.ArrivalDate.SetFocus
  4.         Exit Sub
  5. End If
Aug 20 '15 #1

✓ answered by Seth Schrock

Expand|Select|Wrap|Line Numbers
  1. Dim blnSuccess as Boolean
  2.  
  3. blnSuccess = True
  4.  
  5. Me.Recordset.MoveFirst
  6. Do While Not Me.Recordset.EOF
  7.     If Me.ArrivalDate & "" = "" Then
  8.         blnSuccess = False
  9.         Exit Do
  10.     End If
  11.     Me.Recordset.MoveNext
  12. Loop
  13.  
  14. If blnSuccess = True Then
  15.     'Perform Update query
  16. Else
  17.     MsgBox "You have not selected an arrival date!", vbCritical + vbOKOnly, "Empty Arrival Date!"
  18. End If
  19.  

8 3358
Seth Schrock
2,965 Expert 2GB
Put this code in your form's Before Update event and replace the Exit Sub with Cancel = True.

This will run before each record gets saved before it moves to the next one, so it will be testing the current record and not let you move on without validation passing.
Aug 20 '15 #2
DoubleD
24
Hi Seth,

The form that loads gives me a set of data based on what was entered in a previous form. I need the validation to happen in the click event of a button on this form, because it needs to run a few insert, update and delete queries.

I need it to check that the arrival date for each line on the continuous form is filled in before it can continue doing everything else.

Doing the validation in the form's before update event does nothing for me.
Aug 20 '15 #3
Seth Schrock
2,965 Expert 2GB
Then you are going to have to loop through your recordset. Do you want it to stop at every line that has a problem or do you want it to just tell you that there are problems once it has gone through all the records?
Aug 20 '15 #4
DoubleD
24
I need it to check if the arrival date has a value and for each line that does not have a value, it must throw message box stating that no date was entered.
Aug 20 '15 #5
Seth Schrock
2,965 Expert 2GB
But do you want it to stop on that record so that you know which one failed, or just a general message that one failed?
Aug 20 '15 #6
DoubleD
24
Having it stop on that record will be helpful.
Aug 20 '15 #7
Seth Schrock
2,965 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. Dim blnSuccess as Boolean
  2.  
  3. blnSuccess = True
  4.  
  5. Me.Recordset.MoveFirst
  6. Do While Not Me.Recordset.EOF
  7.     If Me.ArrivalDate & "" = "" Then
  8.         blnSuccess = False
  9.         Exit Do
  10.     End If
  11.     Me.Recordset.MoveNext
  12. Loop
  13.  
  14. If blnSuccess = True Then
  15.     'Perform Update query
  16. Else
  17.     MsgBox "You have not selected an arrival date!", vbCritical + vbOKOnly, "Empty Arrival Date!"
  18. End If
  19.  
Aug 20 '15 #8
DoubleD
24
Great! This works exactly the way I need it to. Thank you so much Seth!
Aug 20 '15 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Prakash Wadhwani | last post by:
Is there any EASY way to highlight a full row in a continuous form so that as i navigate up & down the table/continuous form using the arrow keys, the entire line (all fields) get highlighted ? ...
4
by: Kathy | last post by:
What is the standard technique for handling the fields in the following scenario on a continuous form? Multiple Divisions. Each Division has multiple Buildings. Each Building has a Supervisor. ...
20
by: Robert | last post by:
Need some help to stop me going around in circles on this one.... Have a nested subform (subform2) which simulates a continuous form for the record on the parent subform. Subform2 has rows of...
2
by: bobh | last post by:
Hi All, In Access97 I have a form setup as a continuous form several of the bound controls have calculations that are done in the 'after update' event via VBA code and all works fine. My...
3
by: S P Arif Sahari Wibowo | last post by:
Hi! I would like to make an editable continous form, where most fields will be from table A and editable, except 1-3 fields are a glimpse into table B and uneditable. Table A relate to table B...
5
by: Michael R | last post by:
Searching the net I've found a simple technique to add row numbers and alternate colors (for the even and the uneven row) to a continuous form. 1st step: Create a textbox, send it to background...
5
by: fauxanadu | last post by:
I have a continuous form and a button in the header of the form. When I click the button, the following code is executed: Private Sub cmdTest_Click() Dim objControl As Control ...
2
by: Ian Anderson | last post by:
Hello there, SO i have the followign VB code in my continuous form... 'Purpose: This module illustrates how to create a search form, _ where the user can enter as many or few...
6
by: Jeroen3131 | last post by:
Hello, I'm developing a database where workinstructions (which consist of Steps) can be created and edited. I'v already completed the "Create" form and it works flawless. Now I'm stuck on the Edit...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.