Results 1 to 5 of 5
  1. #1
    vkumar is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    30

    Unhappy Need help to clear a Form Field

    have this code:

    Private Sub
    Job_Number_BeforeUpdate(Cancel As Integer)
    If
    IsNull(DLookup("[Job Number]", "Job", "[Job Number]= " & Me.[Job Number]
    & " ")) Then


    MsgBox "Job Number doesn't exist Enter a job
    number that already exist."
    Me.[Job Number].Undo
    Cancel = True
    End If
    End Sub

    It is not clearing the Job Number Field, and also it is not
    letting me to close the form without entering the Job number that already exist.
    If I try to close the form without entering the job number it gives me run time
    error " syntax error (missing operator) query expression '[Job Number] = '."
    Thank you!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    If you use a combobox, entering a non-existent job number could be prevented and this code totally unnecessary.

    I haven't had much luck with the Undo method. Maybe should Undo the form, not just the textbox http://office.microsoft.com/en-us/ac...080753121.aspx

    Or try just setting the textbox to null: Me.[Job Number] = Null
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    vkumar is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    30
    Job table has lots of job number and it changes. It is not static. Users add job number everyday. That's why I do not want the combo box. If I have limiited job numbers and doesn't change I would use the combo box.
    Me. Undo works, but it clears everything else in the form. I tried Null, I still have the same problem. The way I have set up now, the user must enter the correct job number, otherwise they can't close or claer the form. I don't like this, for example if the user enters a new invoice for a new job number, the user must have entered the Job number and other info in the Job table. If the user forgot to enter this before coming to the Invoice form, the user must enter a Job number that already exist and then close the form or clear the form and close it to go back and enter new the job info in the job table.
    Thank you again for your replies

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Still not understanding resistance to combobox. I expect new job numbers would be created. As stated earlier, the combobox can deal with new numbers while also assisting user with selection of existing job number.

    Your code doesn't allow the entry of a new job number, it only tells user the entered number doesn't exist and they must enter an existing number. How does that accommodate the situation of "Users add job number everyday."?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Subwind is offline Can Only Learn
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Location
    Portsmouth, UK
    Posts
    61
    Combo box is what you want, with a timer requery to update new jobs on the fly.

    Set the form source to be the jobs record and have the combo box set to find the data afterupdate.

    Much easier than the code you have.

    ~Matt

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

Similar Threads

  1. Clear Form
    By hithere in forum Access
    Replies: 4
    Last Post: 03-28-2012, 09:28 AM
  2. Search field will not clear
    By SemiAuto40 in forum Programming
    Replies: 1
    Last Post: 10-13-2011, 08:23 PM
  3. Replies: 2
    Last Post: 10-07-2011, 11:57 AM
  4. Clear a Field OnClick
    By eww in forum Forms
    Replies: 3
    Last Post: 08-19-2010, 01:55 PM
  5. clear field values
    By surrendertoo in forum Queries
    Replies: 0
    Last Post: 02-23-2008, 10:57 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