Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / December 2007

Tip: Looking for answers? Try searching our database.

Opening form at a new record

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
anthony - 30 Dec 2007 15:22 GMT
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
anthony - 30 Dec 2007 15:37 GMT
Ah, moving "DoCmd.GoToRecord , , acNewRec" right to the beginning of
the code seems to have worked
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.