Solved

Why Access 2007 Object Required error

Posted on 2009-03-29
12
600 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

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…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

773 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