Solved

Why Access 2007 Object Required error

Posted on 2009-03-29
12
598 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
  • 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
 

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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
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 - 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
    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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

747 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

12 Experts available now in Live!

Get 1:1 Help Now