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!

Access 2003: “Update or CancelUpdate without AddNew or Edit” error

Status
Not open for further replies.

ernigles

Technical User
Jan 15, 2009
31
ES
Hi, I have a main form about vegetable species which include information about common name, scientific name, crop group, fruit and taxonomy. The target of the database is to visually identify each specie through several corresponding images, so that main form has a continuous subform (sec1) with two textboxes: the image denomination -imageDen- and the name of the image jpg file –fileName- (both no required fields, with validation by code). And the main form has also a simple subform (sec2) that displays the image that matchs with the selected record in the continuous subform. When inserting a new record (a new image), you must write in the textbox named imageDen the image denomination and then press Enter, which makes a browsing dialog window appears. By selecting the jpg file in that dialog window, the code inserts the file name in the textbox named fileName of the continuous subform and also inserts the image like an OLE Object in the simple subform and displays that image on it. By clicking in a label in the main form you also can change that image. The OnClick event of the label has the code:





Private Sub labelChangeImage_Click()
On Error GoTo Error

Dim strFilter As String
strFilter = ahtAddFilterItem(strFilter, ".jpg")

strInputFileName = ahtCommonFileOpenSave(ahtOFN_FILEMUSTEXIST, _
"", strFilter, , ".jpg", "", "Imagen para '" & Me.Sec1.Form!imageDen & "':", hwnd, True)

If Not IsEmpty(strInputFileName) And Not strInputFileName = "" And Mid(strInputFileName, Len(strInputFileName) - 3, 4) = ".jpg" Then
AgregoNombrearchivo strInputFileName, Me.Sec1.Form![theFileName]
todoBienFoto = True
DoCmd.RunCommand acCmdSaveRecord
idEspecie = Me.Id
IdEstaFoto = Me.Sec1.Form!IdFoto
introNombreArchivo = True

idFotoPublicParaTexto = Me.Sec1.Form!IdFoto
Me.Sec2.Form!CtrlActiveX0.ImageLoadFile (strInputFileName)
Me.Sec1.Form.Refresh

cambiaFoto = True
regActu = Me.CurrentRecord - 1

If Me.Sec1.Form.Dirty Then
Me.Sec1.Form.Dirty = False
End If
If Me.Sec2.Form.Dirty Then
Me.Sec2.Form.Dirty = False
End If

Me.textoDesenfoque.SetFocus

ElseIf Mid(strInputFileName, Len(strInputFileName) - 3, 4) <> ".jpg" Then
MsgBox "El archivo de imagen debe ser .jpg.", 64, ""
End If

Error::
If Err.Number = 5 Then
End If
End Sub



Public Function AgregoNombrearchivo(strFile As String, ByRef Field As Object)
If Len(Dir(strFile)) > 0 Then
Dim nombreFile As String
Field = Dir(strFile)
Else
MsgBox "Error: File not found", vbCritical, "Error reading file in FileToBlob"
End If
End Function




Tha main form has two ‘versions’: editable (frmEditarGeneral) and non editable (frmVerGeneral), also with different added functions. If you open the editable version from the non editable version with the code:

Dim rsttt as Variant
Set rsttt = Forms.frmVerGeneral.recordSet
DoCmd.OpenForm "frmEditarGeneral"
Set Forms!frmEditarGeneral.recordSet = rsttt
DoCmd.Close acForm, "frmVerGeneral"



two problems appear:

1.- being in the last main record, if it has no image added, when adding an image and after changing that image file (by clicking the label labelChangeImage), if you go to another main record the error message “Update or CancelUpdate without AddNew or Edit” appears, with two buttons (Ok and Help). This behaviour doesn’t occur when there’s already an image in the last main record, or when it isn’t the last main record.

2.- When deleting a main record by clicking an image in a subform of the main form with the code

Dim cn As ADODB.Connection
Dim strQuery as String
strQuery = "DELETE tblTaxonomia.* FROM tblTaxonomia WHERE tblTaxonomia.Id=" & Me.Parent.Form.Id & ";"
Set cn = CurrentProject.Connection
cn.Execute strQuery
Me.Parent.Requery

the line Me.Parent.Requery doesn’t enter (the main record deleted appears with the value ‘Eliminated’ in all the fields) or it gives the error 3219 in running time: Reserved error.



These two problems don’t occur if i open the editable version form (frmEditarGeneral) directly and not from the non editable version form.


Can anybody say a way of going around these two errors?

Thanks for any help given.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top