Why Access 2007 Object Required error

Posted on 2009-03-29
Last Modified: 2012-05-06
I have an Access 2007 form named frmCreateBatch with a textbox named Client.  I have a string variable Where.

Here is the line of code causing the error:

Where = IIf([Forms]![frmCreateBatch]![Client] Is Not Null, [Forms]![frmCreateBatch]![Client], "Now is the time")

If I don't enter anytihing in the textbox, I simple want to set the var Where to a string value, in this sample "Now is time"

What am I missing?
Question by:willis1970
  • 6
  • 6
LVL 75
ID: 24013489
Where  (no pun) does this code exist ?


Author Comment

ID: 24013529
There is a button on the from and the code is in the click event for that button.

Private Sub btnBuildBatch_Click()
Dim Where As String
Where = IIf([Forms]![frmCreateBatch]![Client] Is Not Null, [Forms]![frmCreateBatch]![Client], "Now is the time")
end sub
LVL 75
ID: 24013610
Is frmCreateBatch open when you click the button ?


Author Comment

ID: 24013836
Yes, the form is open.
LVL 75
ID: 24013886
I assume 'Client' is the Control source for a text box - and the Name property of the text box is the same?

If so ...  rename the Control to


then modify the code as follows:
Where = IIf([Forms]![frmCreateBatch]![txtClient] Is Not Null, [Forms]![frmCreateBatch]![txtClient], "Now is the time")


Author Comment

ID: 24020653
Thanks Genius for your reply.  The name of the text box is client, and there is no control source.  I did a test form, and put one text box on the form named StatusCode, and in the click event of a button,
I set a variable as follows:
SCode = [Forms]![frmCreateBatch]![statusCode]
I get the same object required error, but when I go to the immediate window and type
? [Forms]![frmCreateBatch]![statusCode], it prints "WX" which is the text in the textbox.
I seem to just get the error in code.  Very perplexing....  Any suggestions???
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

LVL 75
ID: 24020737
"I set a variable as follows:"

Are you doing this in form 'frmCreateBatch' ?

Can you:

1) Compact & Repair (to shrink the size),
2) Zip up the MDB (to further shrink the size)
3) Attach the file for upload here (using the 'Attach File function below) ... removing any sensitive data of course.
4** And please give a clear explanation of exactly how to reproduce the problem or what you are trying to do.


Author Comment

ID: 24021731
I'll get that done, and attach the file.  
Thanks, I appreciate the help.

Author Comment

ID: 24022098
I created a text database with one text box, and one button.  Put any text in the text box, and click the command button.
Notice that the debug.print will print what's in the text box, but the program "crashed" with the object required error.
Any suggestions appreciated.
LVL 75

Accepted Solution

DatabaseMX (Joe Anderson - Access MVP) earned 250 total points
ID: 24022308
Make the change below noted with asterisks

Private Sub cmdButton_Click()
    Dim Willis As String
    Debug.Print [Forms]![frmCreateBat]![statusCode]
    If Not IsNull([Forms]![frmCreateBat]![statusCode]) Then   ' **********  HERE
        Willis = [Forms]![frmCreateBat]![statusCode]
    End If
End Sub

Author Closing Comment

ID: 31564069
Feel like saying "DUH!"  I guess the fact that debug.print would handled it, I missed the other (and the syntax if.... IS NOT NULL t works in a SQL statement, I missed the other.  Thanks so much for your help.
LVL 75
ID: 24023890
"Grade:  A - "Feel like saying "DUH!"  I guess the fact that debug.print would handled it, I missed the other (and the syntax if.... IS NOT NULL t works in a SQL statement, I missed the other.  Thanks so much for your help."  "

You are welcome.


Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now