Cannot update fields

shamas21

Registered User.
Local time
Today, 19:32
Joined
May 27, 2008
Messages
162
Hi All

I am trying to update some records on my form.
The forms connect the fields in table 1 to the fields in my form.
When i try to make modifcations to the fields on my form, it wont update the table thats its connected to.

It says 'Fields cannot be updated'

What is the problem?

Code:
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
 
Private Sub btnNext_Click()
 
UpdateRecords
 
rs.MoveNext
 
    If rs.EOF Then
        rs.MoveLast
    End If
 
FillControls
 
End Sub
 
Private Sub btnPrevious_Click()
 
UpdateRecords
 
rs.MoveNext
    If rs.BOF Then
        rs.MoveFirst
    End If
 
FillControls
 
End Sub
 
Private Sub Form_Load()
 
Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
 
rs.Open "Table1", cn, adOpenDynamic, adLockBatchOptimistic
 
FillControls
 
End Sub
 
Sub FillControls()
 
txtID.SetFocus
txtID.Text = rs.Fields.Item("ID")
txtForename.SetFocus
txtForename.Text = rs.Fields.Item("Forename")
txtSurename.SetFocus
txtSurename.Text = rs.Fields.Item("Surename")
 
End Sub
 
Sub UpdateRecords()
 
txtID.SetFocus
rs.Fields.Item("ID") = txtID.Text
txtForename.SetFocus
rs.Fields.Item("Forename") = txtForename.Text
txtSurename.SetFocus
rs.Fields.Item("Surname") = txtSurename.Text
 
rs.UpdateBatch
 
End Sub
 
If you have the form linked to the table you don't need code to to the update. To use the code you have to break the link and use code not only to update but also to load the desired record.
 
If you have the form linked to the table you don't need code to to the update. To use the code you have to break the link and use code not only to update but also to load the desired record.

I have broken the link between my form and the table. So as it stands now it only has a link created with the code i posted earlier, but it still says fields not updatable.

I there a problem with the textboxes its self? do i need to allow updating or something? Maybe its something to do with the following code?

Code:
Sub UpdateRecords()
txtID.SetFocus
rs.Fields.Item("ID") = txtID.Text
txtForename.SetFocus
rs.Fields.Item("Forename") = txtForename.Text
txtSurename.SetFocus
rs.Fields.Item("Surname") = txtSurename.Text
rs.UpdateBatch
End Sub
 
For petes sake , ever since u started ur project and u r trying to achieve something so small with as much code as possible , now for a start why would a professional try and help with a code that's so puffed up , why wouldnt u ask for how it would be done than rather brake it and ask professionals to fix it ?

for a start u move with the dao record curser in a hubhazard way that i cant make my mind what u r trying to do , could this be ur problem ?
 

Users who are viewing this thread

Back
Top Bottom