Simple simple code help please...

AlexB

Registered User.
Local time
Today, 22:20
Joined
Mar 3, 2003
Messages
21
Hello there

I've got a problem with some code that I'm trying to write behind a button. All it will eventually do is just transfer the values from some text fields into a table...

Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("select * from tblProjects")

When I click the button it gets stuck on the SET RST line... with an error 13 - type mis-match.

I haven't got a clue why it's not working; the exact same code behind another button (with a different table name) works fine.

Any suggestions?

Cheers
 
Don't forget the semi-colon at the end of an SQL statement:

Set rst = CurrentDb.OpenRecordset("select * from tblProjects;")
 
Thanks for the reply, but I've still got the problem...

This is my code:

Option Compare Database
Private Sub cmdAddEmployee_Click()

Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("select * from EmployeeDetails;")

rst.AddNew
rst!EmployeeDepartment = comboDepartment
rst!EmployeeMainSkill = comboMainSkill
rst!EmployeeSecondarySkill = comboSecSkill
rst!EmployeeSupervisor = comboSupervisor
rst!EmployeeName = txtEmployeeName
rst!JobTitleID = comboJobTitle
rst.Update
rst.Close
MsgBox ("Employee Added to System.")
DoCmd.Close

MsgBox (comboDepartment)
MsgBox (comboMainSkill)
MsgBox (comboSecSkill)
MsgBox (comboSupervisor)
MsgBox (comboJobTitle)
MsgBox (txtEmployeeName)

End Sub


It's really confusing me now, I can't understand why it doesn't work. It should at least get past the SET RST bit, should it not?

Would it have anything to do with the relationships that my tables are associated with?
 
Try checking your references, and make sure they've not become unset somehow.
 
Ok, the references I have checked at the moment are:

- Visual Basic for Applications
- Microsoft Access 10.0 Object Library
- OLE Automation
- Microsfot ActiveX Data Objects 2.1 Library
- Microsoft ActiveX Data Objects Recordset 2.5 Library
- Microsoft DAO 3.6 Object Library

Is there anything else that I need to be referenced in order for it to work?
 
If that's the order they are in, move the DAO 3.6 priority up by 2 places, underneath OLE automation.
 
Ahhhh.. ah.. ahaha...

Yes it works now, it just gets stuck on the next bit!

Cheers Mile-o-Phile
 
AlexB said:
Code:
    DoCmd.Close

    MsgBox (comboDepartment)
    MsgBox (comboMainSkill)
    MsgBox (comboSecSkill)
    MsgBox (comboSupervisor)
    MsgBox (comboJobTitle)
    MsgBox (txtEmployeeName)

End Sub

Also, this will give you an error as you are closing the form and then trying to use a messagebox to display control values when they will no longer be available.
 
Sorry, me again...

Is there any reason, when using the code from my previous message, that I should get a "Cannot update. Database or object is read-only. (Error 3027)" error?

I've read the help and it says about using the OpenDatabase method (which I haven't... have I?),
Using the data control and setting the ReadOnly property control to True (nope)
Or
Database file is stored on read only media...

Sorry to sound like a gimp, but I just don't understand.

Any help is much appreciated!
 
I've just figured out why I can't use the RST.AddNew command thing.

I'm using Combo Boxes on my form to allow the users of the form to select people from a table, and these are based on a query of the table.

I noticed that when I open the form, and then look at the table, I cant add anything into the table as it's locked.

Is this because I'm using the wrong type of query (it's just a SELECT)?

How would I get around this problem - I need a combo box of sorts so people can choose from a list of people, rather than making them put it in manually. Am I right in basing the combo boxes on a query of the database, or am I going about this the wrong way?

Sorry to keep asking questions, but Im crap at databases!
 
I've just figured out why I can't use the RST.AddNew command thing.

I'm using Combo Boxes on my form to allow the users of the form to select people from a table, and these are based on a query of the table.

I noticed that when I open the form, and then look at the table, I cant add anything into the table as it's locked.

Is this because I'm using the wrong type of query (it's just a SELECT)?

How would I get around this problem - I need a combo box of sorts so people can choose from a list of people, rather than making them put it in manually. Am I right in basing the combo boxes on a query of the database, or am I going about this the wrong way?

Sorry to keep asking questions, but Im crap at databases!

Thankyou kindly
 
Sorry, I can't say as I've never had a problem like this before.
 
It suddenly worked earlier, but I posted a reply in the wrong thread.. oops

Cheers again for your help, Im actually making progress now
 
Yeah, I saw that - I never would have suspected you had the table physically open.
 

Users who are viewing this thread

Back
Top Bottom