Opening form at a new record

Opening form at a new record

am 30.12.2007 16:22:36 von anthony

I'm a bit perplexed about this. If I bring the form out of design mode
into view mode, then the code below (which is on the form's open
event) works fine and gives me a new record. If I close the form
completely and then re-open it, I get the error "GoToRecord isn't
available now". How do I get around that?

On Error GoTo errH
Dim DB As Database
Dim RST As Recordset
Dim strSQL As String
Dim strFileName As String 'the photo's filename
Dim strPath As String 'path to the photos folder
Dim strCompletePath As String 'path and filename combined
Dim strPhotoID As String 'use to get the ID of the photo in img1
Set DB = CurrentDb()

DoCmd.OpenForm "frmPath", , , , , acDialog
strPath = Forms!frmPath!txtPath
If strPath = "" Then
MsgBox "You need to fill in the path to the folder where the
photos live eg c:\data\igdb\photos"
GoTo X
End If
Me.txtPath = strPath
DoCmd.Close acForm, "frmPath", acSaveNo
Select Case fnAnyRecords
Case 0
strSQL = "SELECT PhotoID, Photo FROM tblPhoto ORDER BY Photo;"
Set RST = DB.OpenRecordset(strSQL)
With RST
..MoveFirst
strFileName = !Photo
strPhotoID = !PhotoID
strCompletePath = strPath & "\" & strFileName
Me.img1.Picture = strCompletePath
..MoveNext
strFileName = !Photo
strCompletePath = strPath & "\" & strFileName
Me.img2.Picture = strCompletePath
..MoveNext
strFileName = !Photo
strCompletePath = strPath & "\" & strFileName
Me.img3.Picture = strCompletePath
End With
Case Is > 0
strSQL = "SELECT Photo, PhotoID FROM tblPHOTO"
strSQL = strSQL & " WHERE (((tblPhoto.Photo)>" & "'" & fnLastRecord &
"'" & "))"
strSQL = strSQL & " ORDER BY Photo;"
Set RST = DB.OpenRecordset(strSQL)
With RST
..MoveFirst
strFileName = !Photo
strPhotoID = !PhotoID
strCompletePath = strPath & "\" & strFileName
Me.img1.Picture = strCompletePath
..MoveNext
strFileName = !Photo
strCompletePath = strPath & "\" & strFileName
Me.img2.Picture = strCompletePath
..MoveNext
strFileName = !Photo
strCompletePath = strPath & "\" & strFileName
Me.img3.Picture = strCompletePath
End With
End Select
DoCmd.GoToRecord , , acNewRec
Me.txtPhotoID = strPhotoID
Me.cboCATID.SetFocus
X:
Exit Sub
errH:
MsgBox Err.Description & Err.Number
Resume X

Re: Opening form at a new record

am 30.12.2007 16:37:58 von anthony

Ah, moving "DoCmd.GoToRecord , , acNewRec" right to the beginning of
the code seems to have worked