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!

Writing from form to a table 2

Status
Not open for further replies.

mayday999

Technical User
Nov 20, 2006
17
US
Hi all,

I have a form that has two unbound list boxes, I then have a command button which is supposed to write a record two a table when clicked. The table has three fields, a Primary key (autonumber) Then two foreign key fields, which the two list box values should populate. I have the following code attached to the button:

Private Sub Command3_Click()
On Error GoTo Err_Command3_Click


Dim dbAssesmentTool As DAO.Database
Dim rstAssesment As DAO.Recordset

Set dbAssesmentTool = CurrentDb
Set rstAssesment = dbAssesmentTool.OpenRecordset("tblAssessmentlink")

rstAssesment.AddNew
rstAssesment("AssessmentID").Value = AssessmentName
rstAssesment("SiteID").Value = SiteName
rstAssesment.Update


Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click

End Sub

On clicking i get an "Item not found in this collection" message... I don't know whats going on, I use the same code for another function and it works fine. can anyone please help???

TIA

mayday
 
Just a wild shot in the dark, but you will get this error if the table name or a field name has been mis-spelled.

Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.
 
Code:
   rstAssesment("AssessmentID").Value = AssessmentName
   rstAssesment("SiteID").Value = SiteName

Almost for sure that the table doesn't contain a field called "AssessmentID" or "SiteID". Or maybe you are opening the wrong table?
 
Just got back to this, you are both right, I was missing an "S" at the end of the table name. That drove me crazy! Thank you both for your responses!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top