Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Object Required" error in Access Form 5

Status
Not open for further replies.

BYarn

MIS
Jul 20, 1999
131
US
I know this question may be too general but here goes. I Have an Access 2000 form. When the account # field is completed it will pull data from an exisiting table to automatically complete three other form fields from the record of the person with the account #. After that there are a few drop down boxes which are completed manually. All of the data ends up in another table.

When I click the SAVE button to store the data, I get an "Object Required" error button that pops up. I have to cancel out and no new data goes to the table.

My question- can anyone point me as to what kinds of things to look for that might eliminate the erro and allow the data to be stored. I have spent hours looking over the code and testing to no avail!! Thanks
 
What's the code that errors out? Does it highlight a specific line of code?

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
no it doesn't.I run the form, complete it and click save at which point I get the error.
 
Ive gotten that error from something as simple (and easy to not think of) as a missing reference. Have you checked those?

Let them hate - so long as they fear... Lucius Accius
 
An example of code that will give an Object Required error:

[tt]Dim rs As DAO.Recordset

Set rs = Db.OpenRecordset("select * from tblTable")[/tt]

The reason is that DB is not set to an object (currentdb), hence an object is required. Any code that references an object, such as a form, as an object, but does not set it as an object first, will give such an error.
 
I **trully** appreciate the offer to look @ the code. I am not sure (my intuition tells me no) that I am allowed to do that (employer may not appreciate)

Don't want you spinning your wheels but if it helps perhaps I can give you some info:
1) I am using 2 tables (different DBs) one that has the data used to complete some of the blanks in my form. and a second table to hold the new data plus the stuff pulled from the other table
2) The form is a typical fill in the blanks, where after entering the acct #, it extracts the 1st and last name as well as an ID number. You then fill in a couple of other new fields. There is also a SAVE, CANCEL and EXIT button.

I have no trouble with cancel or exit. Also, all the fields get filled in the way they should. It is ONLY when I click SAVE that I get an "Object Required" message on with an OK button.

I can not find what is missing ans have spend a bunch of time. I thank you for your efforts.!!!!!!!!!!
 
If you do not want to post the 'save' code then just put a breakpoint into the 'save' code and follow it down (f8) one line at a time until it breaks.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
GingerR had a good suggestion - If you post the code behind the SAVE button, it would make a huge difference in people's ability to help.
You can change any field/table names which may be referenced for privacy's sake.

Let them hate - so long as they fear... Lucius Accius
 
I thank everyone for your help. I realize I didn't provide much to work with, but you were willing to help anyway!My intuition tells me I shouldn't post any part of the code and I don't want to waste anyone time! Thanks again!!
 
Why not? I can't imagine that it divulges any trade secrets. We all post code here all the time.

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
We do indeed, it is quite easy to leave out anything specific, ctlControl could hardly worry the most nervous secret agency. :)
 
This should be all the code for the save button. Note that I played with it and instead of a button with the text “object required” appearing, now when the save button is clicked it generates the error msg “You Need to Fix Your Code” and that is as far as it goes. I replaced any identifying info with an X.


Private Sub btnSave_Click()
Dim vDate As Date
Dim NullField

On Error GoTo errorSave

NullField = txtFind
If IsNull(NullField) Or NullField = "" Then
MsgBox "You must enter a XXX or XXX."
txtFind.SetFocus
Exit Sub
End If
NullField = txtLastName
If IsNull(NullField) Or NullField = "" Then
MsgBox "You must enter a Last Name."
txtLastName.SetFocus
Exit Sub
End If
NullField = txtFirstName
If IsNull(NullField) Or NullField = "" Then
MsgBox "You must enter a First Name."
txtFirstName.SetFocus
Exit Sub
End If
NullField = txtWk_No
If IsNull(NullField) Or NullField = "" Then
MsgBox "You must enter a XXX Number."
txtWk_No.SetFocus
Exit Sub
End If

vDate = Format(Now, "mm/dd/yyyy")
tbl_xxx_xxxxx.AddNew
rstbl_xxx_xxxxx.Fields("de date") = vDate
rstbl_xxx_xxxxx.Fields("last name") = UCase$(Left$(txtLastName, 1)) & LCase$(Right$(txtLastName, Len(txtLastName) - 1))
rstbl_xxx_xxxxx.Fields("first name") = UCase$(Left$(txtFirstName, 1)) & LCase$(Right$(txtFirstName, Len(txtFirstName) - 1))
rstbl_xxx_xxxxx.Fields("xx, xxx or xx#") = txtFind
rstbl_xxx_xxxxx.Fields("xx_xx") = xx_xx

tbl_xxx_xxxxx.Update

vAddNew% = False
txtFind.SetFocus

txtFind.Text = ""
txtLastName = ""
txtFirstName = ""
txtXX_XX = ""

txtFind.SetFocus
btnSave.Enabled = False
btnCancel.Enabled = False
Exit Sub
errorSave:
Err.Description = "You Need to Fix Your Code!"
MsgBox Err.Description
Exit Sub
End Sub
 
Hi, not sure if its a problem, but you haven't declared your "nullField" as a type? I'm kinda new as well so that might not be a problem
 
hi, sorry ignore that last post, it works the way you have it. Think you should do as traingamer suggested and find out which line the program breaks at. That would probably be the best way to find out whats goin on.
 
Are these two mistyping:
tbl_xxx_xxxxx.AddNew
tbl_xxx_xxxxx.Update

According to the above, they should be:
rstbl_xxx_xxxxx.AddNew
rstbl_xxx_xxxxx.Update

I do not see:
Dim rstbl_xxx_xxxxx as DAO.Recordset
Or such like.

Nor do I see:
Set rstbl_xxx_xxxxx = CurrentDB.OpenRecordset("tbl_xxx_xxxxx")
Or equivalent.
 
Remou-made changes-no difference Thanks!!

I did the "breaks" but still can't see what it is!
 
To have a better understanding on where and why the error raise, comment out the following line:
On Error GoTo errorSave

And then say us which line of code is highlighted when in debug mode.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Rem out the On error goto line so when the code breaks and you hit the debug key it will be sitting on the line that is causing the problem. Then tell us what line it is on.

HTH

BYarn,

As a side note I often post code with pseudo variables and such and have always gotten great advice and great solutions to my problems.

Set rs=db.opendatabase("mytable"...)

or

sql="Select field1, field2 from mytable where field1=xxx"

The folks at Tek-Tips are here to help and not try to cause harm. I've gotten help here more times than I can count through starting threads and doing searches for topics.

I tried to have patience but it took to long! :) -DW
 
what's

vAddNew% = False

?

Typically code for adding to a table looks like this:

Dim rs as dao.Recordset
set rs = Currentdb.Openrecordset("Select * from Table1")
rs.addnew

rs!Field1 = me.txtBox1
rs!Field2 = me.txtBox2
rs!Field3 = me.txtBox3

rs.update

set rs = nothing



Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top