recordset

J

jon

hi
Using a record set I am trying to update a field in a second table and when
the code runs it says it can not find the field 'FreeStateCount' So I have
done something wrong
in the table ComponetNos I have a field called 'Componet No' (I know about
the space not being good)
and on the form I have a control box called 'cmbJob' which is the link to
the 'componeteNos' table with the field 'Componet No'
Can some one please point me in the right direction as to where I am going
wrong.
The code is below

Thanks

Jon

Private Sub ButUpdate_Click()
On Error GoTo Err_ButUpdate_Click

Dim db As DATABASE
Dim rst As Recordset



Set db = CurrentDb()
Set rst = db.OpenRecordset("ComponentNos", dbOpenTable)

With rst
rst.Index = "Componet No"
rst.Seek "=", [CmbJob]

DisplayMessage ([FreeStateCount]) 'line in for debugging
DisplayMessage ("5th if") ' delete after debugging
..Edit
![FreeStateCount] = [FreeStateCount] + 1
..Update
End With

DoCmd.Close

Exit_ButUpdate_Click:
Exit Sub

Err_ButUpdate_Click:
MsgBox Err.Description
Resume Exit_ButUpdate_Click

End Sub
 
O

OssieMac

Hi Jon,

The following might help.

When you use With rst you don't repeat the the rst you just put the .
With rst
.Index = "Componet No"
.Seek "=", [CmbJob]

Try addressing the fields this way.
.Edit
.Fields("FreeStateCount") = Fields("FreeStateCount") + 1
.Update
 
J

jon

Thanks Ossie
Sorted

OssieMac said:
Hi Jon,

The following might help.

When you use With rst you don't repeat the the rst you just put the .
With rst
.Index = "Componet No"
.Seek "=", [CmbJob]

Try addressing the fields this way.
.Edit
.Fields("FreeStateCount") = Fields("FreeStateCount") + 1
.Update

--
Regards,

OssieMac


jon said:
hi
Using a record set I am trying to update a field in a second table and
when
the code runs it says it can not find the field 'FreeStateCount' So I
have
done something wrong
in the table ComponetNos I have a field called 'Componet No' (I know
about
the space not being good)
and on the form I have a control box called 'cmbJob' which is the link to
the 'componeteNos' table with the field 'Componet No'
Can some one please point me in the right direction as to where I am
going
wrong.
The code is below

Thanks

Jon

Private Sub ButUpdate_Click()
On Error GoTo Err_ButUpdate_Click

Dim db As DATABASE
Dim rst As Recordset



Set db = CurrentDb()
Set rst = db.OpenRecordset("ComponentNos", dbOpenTable)

With rst
rst.Index = "Componet No"
rst.Seek "=", [CmbJob]

DisplayMessage ([FreeStateCount]) 'line in for debugging
DisplayMessage ("5th if") ' delete after debugging
..Edit
![FreeStateCount] = [FreeStateCount] + 1
..Update
End With

DoCmd.Close

Exit_ButUpdate_Click:
Exit Sub

Err_ButUpdate_Click:
MsgBox Err.Description
Resume Exit_ButUpdate_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top