Solved

Why Access 2007 Object Required error

Posted on 2009-03-29
12
605 Views
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?
0
Comment
Question by:willis1970
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 75
ID: 24013489
Where  (no pun) does this code exist ?

mx
0
 

Author Comment

by:willis1970
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
0
 
LVL 75
ID: 24013610
Is frmCreateBatch open when you click the button ?

mx
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:willis1970
ID: 24013836
Yes, the form is open.
0
 
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

txtClient  

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

mx
0
 

Author Comment

by:willis1970
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???
0
 
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.

mx
0
 

Author Comment

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

Author Comment

by:willis1970
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.
Test.mdb
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) 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
    Stop
    End
End Sub
0
 

Author Closing Comment

by:willis1970
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.
0
 
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.

mx
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

636 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