Results 1 to 8 of 8
  1. #1
    cheyanne is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Location
    Valencia, Spain
    Posts
    91

    Syntax problem

    I want to make a field blank after an entry has been erroneously made and


    a MsgBox has advised the user that the entry they have made is incorrect.

    Foe example I have a date field (formatted to short date) which requires the user
    to input a date greater than today. I have got the MsgBox to work but keep getting
    error messages with the code below the MsgBox line. Ideally I want the user to be returned to
    that date field which should be blank allowing them to enter a correct value.

    Code:
       If txtNextAppointment < Date Then
          MsgBox "Entre una fecha más que hoy", vbOKOnly (This is Spanish for "Enter a date greater than today")
          Me.Undo
       End If
    .

    The above code returns today´s date, and puts it in the txtNextAppointment field, albeit it was never placed in that field by the user.

    I have tried other pieces of code e.g. Me.txtNextAppointment.SetFocus
    Me.txtNextAppointment.Value = ""
    Me.txtNextAppointment.Cancel

    I am sure it will be a simple line of code, but I cannot find the correct syntax.

    Any help will be much appreciated.

    Regards

    Cheyanne

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Try this in the controls Before Update event:
    Code:
       If Me.ActiveControl < Date Then
          MsgBox "Entre una fecha más que hoy", vbOKOnly (This is Spanish for "Enter a date greater than today")
          Cancel = True
       End If
    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
    cheyanne is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Location
    Valencia, Spain
    Posts
    91
    Hi Bob

    Thanks for your assistance. I entered the code as suggested but it still shows the date that was entered incorrectly.

    Ideally I would have liked the field to have focus but be blank.

    How can I send my posts in .mdb format?

    Regards

    Cheyanne

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Try this:
    Code:
       If Me.ActiveControl < Date Then
          MsgBox "Entre una fecha más que hoy", vbOKOnly (This is Spanish for "Enter a date greater than today")
          Cancel = True
          Me.ActiveControl.Undo
       End If
    I think this will leave the control showing whatever was showing before the attempted update.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    cheyanne is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Location
    Valencia, Spain
    Posts
    91
    Hi

    You were correct in that it shows whatever was originally stored in that field.

    Many thanks - will mark as solved

    Cheyanne

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    How can I send my posts in .mdb format?
    This may help: http://office.microsoft.com/en-us/ac...#_Toc258329152

    Save a copy of an .accdb file in the .mdb file format

    • On the File tab, click Save & Publish.
    • Under Save Database As, do one of the following:
      • To save a copy of the database in a format that can be opened by using Access 2002 or later, click Access 2002 - 2003 Database (*.mdb).
      • To save a copy of the database in a format that can be opened by using Access 2000 or later, click Access 2000 Database (*.mdb).

    • Click Save As.

      If the database contains any features that prevent you from saving it as an .mdb file, Access displays a message and prevents you from continuing. The next section outlines factors that can prevent saving as an .mdb file. You must address those factors before you can continue with this procedure.
    • In the Save As dialog box, in the File name box, type a name for the database file, and then click Save.

    Access closes the original database and opens a new copy of the database in the format that you specified. Any changes that you make to the database affect only the new copy. To make changes to the original database, you must reopen the original database.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    cheyanne is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Location
    Valencia, Spain
    Posts
    91

    Cannot change to .mdb format

    Hi

    Thanks for your detailed reply

    I did as you suggested but Access advises I cannot change to 2000/2003 format.


    I can appreciate that it would have difficulty converting my database into a 2000/2003 format as a lot has changed in 12 years.

    Howver I am amazed that there is no facility to convert the database into a 2007 format which is much later, assuming of course
    that the Access 2007 had .mdb format in its armoury.

    Regards

    Cheyanne

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    I did as you suggested but Access advises I cannot change to 2000/2003 format.
    Howver I am amazed that there is no facility to convert the database into a 2007 format which is much later, assuming of course
    that the Access 2007 had .mdb format in its armoury.
    A2007 and A2010 both use the .accdb file extention. All earlier versions use the .mdb file extention. Both A2007 and A2010 can convert a file to one which uses the .mdb extention if you have not used one or more of the new features in your DB that were not in A2003.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Replies: 5
    Last Post: 03-30-2012, 09:00 AM
  2. Syntax problem? Strings
    By axess_nab in forum Forms
    Replies: 5
    Last Post: 06-01-2011, 03:21 PM
  3. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM
  4. Please help SQL Syntax
    By jordanturner in forum Access
    Replies: 4
    Last Post: 09-02-2010, 08:05 AM
  5. Syntax Contains Problem
    By pimlicosnail in forum Forms
    Replies: 9
    Last Post: 02-18-2010, 12:16 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