We help IT Professionals succeed at work.

Access - Object Required error

Pdeters
Pdeters asked
on
Medium Priority
578 Views
Last Modified: 2013-11-28
I am trying to update a date field with the current date if a cmd button is hit and the field is empty. If the field is not empty I want to jsut close the form
This is the code I am using. When I hit the command button I get Object Required error. What would be a better way so that this works.

     If Me.date_complete Is Null Then
        Me.date_complete = Date
        DoCmd.Close

    Else
        DoCmd.Close
    End If
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Use

If Isnull(Me.date_complete) Then
        Me.date_complete = Date()
        DoCmd.Close acform, me.name
 Else
        DoCmd.Close  acform, me.name
 End If

I think it is a good idea to be explicit about what you are closing, just in case something else manages to get focus.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
You need to use the IsNull function rather than the Is Null comparison
Cheers, Andrew
    If IsNull(Me.date_complete) Then
        Me.date_complete = Date
    End If
    DoCmd.Close

Open in new window

Author

Commented:
I did not know about IsNull - thank you
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.