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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2000 to 2003 wierd code issues

Status
Not open for further replies.

poporacer

Programmer
Oct 2, 2007
53
US
I have a DB that was written in Access 2000 and works fine, when I try to run in 2003 it doesn't work properly. I tried to run the conversion from 2003 and it didn't fix the issue. The issue is with a form that has several controls (textboxes, checkboxes and comboboxes) I have 3 tables, one for Staff Data, one for Incident data and one for information on Staff in Incident data. I want to check and see if the data has been changed in any of the controls and if so, ask the user if he wants to save the changes. It looks like my problem lies in a function to save the data. I have a couple of functions that are called in this function, they are:

glbstrActiveLogNumber 'is used to get the currently selected incident log number

glbstrActiveIDNumber 'is used to get the currently selected Staff member

ControlPresent "is used to check if there is a field name that matches the control (Control names are the same as relevant field names)


And here is the code that is not working and seems to be the root of the problem:

Code:
Private Function SaveData()
    Dim myControl As Control
    Dim myField As Field
    Dim rstStaff As Recordset
    Dim rstIncidents As Recordset
    
    Set rstIncidents = CurrentDb.OpenRecordset(QuerytblOffense)
    rstIncidents.FindFirst "[LogNum] = '" & glbstrActiveLogNumber & "'"
    If (rstIncidents.NoMatch = False) Then
        rstIncidents.Edit
        For Each myField In rstIncidents.Fields
            If (ControlPresent(myField.Name, Me)) Then
                Set myControl = Me.Controls(myField.Name)
                If (myControl.Tag = "IncidentData") Then
                    rstIncidents(myControl.Name) = myControl
                End If
            End If
        Next myField
        rstIncidents.Update
    End If
    
    Set rstStaff = CurrentDb.OpenRecordset(QueryStaffInIncident)
    rstStaff.FindFirst "[IDNum]='" & glbstrActiveIDNumber & "'"
    If (rstStaff.NoMatch = False) Then
        rstStaff.Edit
        For Each myField In rstStaff.Fields
            If (ControlPresent(myField.Name, Me)) Then
                Set myControl = Me.Controls(myField.Name)
                If (myControl.Tag = "StaffData") Then
                    rstStaff(myControl.Name) = myControl
                End If
            End If
        Next myField
        [highlight]rstInmates.Update 'Error Here [/highlight]
    End If
    Call RefreshMe
End Function

In 2000 this works fine, in 2003 I get an error message:
Run time Error 3218; Could not update, currently locked.

Any suggestions and any other quirks between the two versions that I should look for?
 
do you want rstStaffs not rstInmates?
 
That was a typo...the correct code is rstStaff.Update
 
If you are still having the problem this might help, but I am reaching. Always define your recordset objects explicitly so as not to confuse an ado and dao objects. This can be problematic because in 97 dao was the default, in 2000 ado was the default and in 2003 both were defaulted.

Dim myControl As Access.Control
Dim myField As dao.Field
Dim rstStaff As dao.Recordset
Dim rstIncidents As dao.Recordset

And open the rs as dynaset

CurrentDb.OpenRecordset(QueryStaffInIncident,dbopendynaset)
 
I tried those changes and it still does not work. For some reason the recordset is not updating?? It might be something with the query or relationships, but why work in 2000 and not 2003?
 
Is "QueryStaffInIncident" still an updateable query after your conversion? Open the query and see if it is updateable.
 
I am not sure how to check if it is updateable? I opened the query and looked for properties but could not find where it is updateable
 
You could check if it is updatable by running the query in the query designer and see if you can change or append a record...

Pampers [afro]
Keeping it simple can be complicated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top