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 TouchToneTommy 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 on Forms

Status
Not open for further replies.

rmtiptoes

IS-IT--Management
Mar 30, 2004
55
US
I am getting the above error when I load my form.

' Connect the Data control to the database.
datAssetsDrop.DatabaseName = dbname

Here is the code:

Private Sub Form_Load()
Dim dbname As String
Dim db As dao.Database
Dim rs As dao.Recordset

' Open the database.
dbname = "C:\Documents and Settings\Renee McCown\My Documents\Mylan\Equipment Application\Mylan NODBMenu"
If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
dbname = dbname & "Mylan_NODBMenus.mdb"

Set db = OpenDatabase(dbname)
Set rs = db.OpenRecordset("SELECT AssetsDrop.[PONumber] FROM AssetsDrop ORDER BY AssetsDrop.[PONumber]", dbOpenSnapshot)

' Load the ComboBox.
rs.MoveFirst
Do While Not rs.EOF
PONumber.AddItem rs!PONumber
rs.MoveNext
Loop

rs.Close
db.Close

' Connect the Data control to the database.
datAssetsDrop.DatabaseName = dbname

Homer: But every time I learn something new, it pushes out something old! Remember that time I took a home wine-making course and forgot how to drive?
Marge Simpson: That's because you were drunk!
Homer: And how.

 
How are ya rmtiptoes . . . . .

Unless this is something you have to do on the fly, forget the mess . . . . .

For the combobox:
[ol][li]Set the [blue]Row Source Type[/blue] to [purple]Table/Query[/purple].[/li]
[li]Set the Row Source to:
Code:
[blue]SELECT [PONumber] FROM AssetsDrop [purple][b]In 'C:\Documents and Settings\Renee McCown\My Documents\Mylan\Equipment Application\Mylan NODBMenu\Mylan_NODBMenus.mdb'[/b][/purple] ORDER BY [PONumber];"[/blue]
[/li][/ol]
[purple]Thats It . . .[/purple]

Calvin.gif
See Ya! . . . . . .
 
Hi AceMan1,

Thank you for your response. The problem is I need to allow the users to select the record from four combo boxes:

AssetID
PO Number
OriginalAssetID
Date Received

This was the only code that supposedly would allow all four combo fields to be updated as well as the text boxes. I tried your suggestion earlier and it will not update the other combo boxes, only the text boxes on the form. This was promising. It would update all the texts and combo boxes with the record.

Do you know why I am getting this error? I am sooo confused

Homer: But every time I learn something new, it pushes out something old! Remember that time I took a home wine-making course and forgot how to drive?
Marge Simpson: That's because you were drunk!
Homer: And how.

 
rmtiptoes . . . . .

Is this the external database [blue]Mylan_NODBMenus.mdb[/blue] on a network?



Calvin.gif
See Ya! . . . . . .
 
No. It's on the same server as the app.

Homer: But every time I learn something new, it pushes out something old! Remember that time I took a home wine-making course and forgot how to drive?
Marge Simpson: That's because you were drunk!
Homer: And how.

 
OK rmtiptoes . . . . .

As for your origional code:
[ol][li]At the top & bottom you have:
Code:
[blue]   [green]'Connect the Data control to the database.[/green]
   datAssetsDrop.DatabaseName = dbname[/blue]
Not sure what your doing here but it certainly looks like an [blue]Object is required[/blue]. Is the debugger stopping on this line?[/li]
[li]In the following loop:
Code:
[blue]    Do While Not rs.EOF
        PONumber.[purple][b]AddItem[/b][/purple] rs!PONumber
        rs.MoveNext
    Loop[/blue]
[purple]AddItem[/purple] is a method of comboboxes on Menus & ToolBars, [purple]not forms[/purple]. If you didn't get the object error, an error would occur here.[/li]
[li]
rmtiptoes said:
[blue]This was the only code that supposedly would allow all four combo fields to be updated as well as the text boxes.[/blue]
As you have it posted, I don't see how thats possible, as the SQL in the code [blue]only returns one field[/blue], namely [purple][PONumber][/purple]. I can't see updating three other comboxes in this way. Perhaps you can expand on this?[/li]
[li]
rmtiptoes said:
[blue] I tried your suggestion earlier and it will not update the other combo boxes, only the text boxes on the form.[/blue]
Because the SQL only returns [purple][PONumber][/purple], they could only update to [purple][PONumber][/purple] (unless their all the same . . . depends on how properties for each combo are setup as well). As it stands each combobox requires its own RowSource with the approiate field. The same SQL I provided only requires a change of the [blue]FieldName[/blue] per combobox. So for each combobox you would substitute proper names in ([purple]purple[/purple] below):
Code:
[blue]SELECT [[purple][b]FieldName[/b][/purple]] FROM AssetsDrop In 'C:\Documents and Settings\Renee McCown\My Documents\Mylan\Equipment Application\Mylan NODBMenu\Mylan_NODBMenus.mdb' ORDER BY [[purple][b]FieldName[/b][/purple]];"[/blue]
[/li][/ol]
[purple]Your thoughts . . .[/purple]

Calvin.gif
See Ya! . . . . . .
 
Hi AceMan1,

Lost my internet connection. As for your responses, I studied them diligently and based upon your comments, have come to realize the code I have is not going to work. I can use your queries to set up my combos, thank you very much.

I think I can only give the users two combo boxes rhat sync instead of four with the combo boxes listing the other data. I wanted to let them use four combos to select a record source but I do not think that is possible. Thanks for all of your help AceMan1!!


Homer: But every time I learn something new, it pushes out something old! Remember that time I took a home wine-making course and forgot how to drive?
Marge Simpson: That's because you were drunk!
Homer: And how.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top