Results 1 to 6 of 6
  1. #1
    meena is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    13

    Mandatory Data Entry In Field Before Moving to Another Field

    Below is my code... But it does not seems to work :-(



    1. If my booking ID is blank It displays the error message and enters the next field. Goes through the validation of the next field pops up the message. displays the ID error message and sets the cursor to the last field my form.
    2. I have added in the validation rule = Is Not Null and Validation text = ooking ID cannot be blank
    3. Changed the code from txtbookingid.Setfocus to SendKeys "+{TAB}"
    4. Similar code for other field validation works fine, but for this one I am stuck.

    Not sure where I am going wrong.


    Private Sub txtbookingid_LostFocus()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim MyVal As Long
    Dim strSql As String

    Set db = CurrentDb()

    If Me.txtbookingid = "" Or IsNull(Me.txtbookingid) Then
    MsgBox ("Booking ID cannot be blank")
    SendKeys "+{TAB}"
    Else
    strSql = "SELECT BookingID,StartDate,EndDate,NoAdults,NoChildren " & _
    "FROM Booking_Header " & _
    "WHERE BookingID = " & Me.txtbookingid & "" & _
    "AND BookingStatus NOT IN ('COMPLETED','CANCELLED')"

    Set rs = db.OpenRecordset(strSql, dbOpenDynaset)


    If rs.RecordCount = 0 Then
    MsgBox (" Please enter the customer details before planing the Itinerary")
    Me.txtbookingid = ""
    SendKeys "+{TAB}"
    Else
    Me.txtstartdate = (rs!Startdate)
    Me.txtenddate = (rs!Enddate)
    Me.txtNA = (rs!NoAdults)
    Me.txtNC = (rs!NoChildren)
    End If

    rs.Close
    Set rs = Nothing
    Set db = Nothing

    End If

    End Sub

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    IMHO it is best to put validation code in the before Update event which can be cancelled.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Mar 2012
    Posts
    528
    An example of a professor (ItsMe )
    Under the name (Parts Issue)
    This is a copy of which he was a very nice
    not leave the field empty
    Attached Files Attached Files

  4. #4
    meena is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    13
    My form is an unbound form. I want to validate each field and ensure proper data is entered before the user jumps to the next field. When my I open my form, my code is not triggered and moves to the next field. However if I key in something & clear it then it recognizes it as null and triggers my code. Hope to have some guidance.

    Private Sub txtstartdate_BeforeUpdate(Cancel As Integer)


    If IsNull(Me.txtstartdate) = True Or Me.txtstartdate = "" Then
    MsgBox ("Please enter the Itinerary Startdate before you proceed")
    Cancel = True
    ElseIf Me.txtstartdate <= Me.txtbookingdate Then
    MsgBox (" Trip Start Date should atleast be 20 days after Enquiry date ")
    Cancel = True
    End If


    End Sub

  5. #5
    meena is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    13
    Quote Originally Posted by Bob Fitz View Post
    IMHO it is best to put validation code in the before Update event which can be cancelled.
    I did try but doesn't seem to work.

    My form is an unbound form. I want to validate each field and ensure proper data is entered before the user jumps to the next field. When my I open my form, my code is not triggered and moves to the next field. However if I key in something & clear it then it recognizes it as null and triggers my code. Hope to have some guidance.

    Private Sub txtstartdate_BeforeUpdate(Cancel As Integer)


    If IsNull(Me.txtstartdate) = True Or Me.txtstartdate = "" Then
    MsgBox ("Please enter the Itinerary Startdate before you proceed")
    Cancel = True
    ElseIf Me.txtstartdate <= Me.txtbookingdate Then
    MsgBox (" Trip Start Date should atleast be 20 days after Enquiry date ")
    Cancel = True
    End If


    End Sub

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Why are you using a Unbound Form? Using Unbound Forms does away with the primary reason for using Access, which is to take advantage of it ability to facilitate the RAD (Rapid Application Development) of Databases!

    With Bound Forms, Access does the vast majority of the heavy lifting; with Unbound Forms the developer has to write code for just about everything, even the most mundane tasks. Several developers I know, experienced in Visual Basic database development, as well as Access development, estimate that development, using Unbound Forms, by highly experienced developers, takes two to three times as long, using Unbound Forms, as it does when using Access and Bound Forms.

    In short, there is very little that can be done using Unbound Forms that cannot be accomplished with Bound Forms, and usually done with much less work!

    Anyone who insists on using Unbound Forms, would be far better off using a straight VB or C++ front end with a SQL Server or Oracle back end.

    • You can create an EXE file which gives total protection to your code/design
    • You can distribute the db to PCs without a copy of Access being on board
    • Your data security is far, far better than anything you can do in Access


    It should be added that there are a few very specialized reasons for using Unbound Forms in Access, for general data entry of Records, but they are very specialized, and situations that a newbie is very unlikely to come upon. I've been writing Access apps for well over a decade now, and have never had the need for using Unbound Forms for general data entry.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 12-31-2013, 02:53 PM
  2. Replies: 1
    Last Post: 11-04-2011, 06:53 AM
  3. Automatic Field DAta Entry
    By Lupson2011 in forum Access
    Replies: 4
    Last Post: 09-01-2011, 09:15 AM
  4. Save as Draft but mandatory field is not required
    By zuerin in forum Programming
    Replies: 5
    Last Post: 06-30-2011, 01:42 AM
  5. Replies: 3
    Last Post: 03-05-2011, 12:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums