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!

Bookmark not being set

Status
Not open for further replies.

bwilkens

Programmer
Feb 4, 2002
7
US
I found this example somewhere and use it to save my main form and have two more subs similar to this to save two subforms in case the user wants to undo the data. It was working at one point but now the bookmark is always zerolength as it would be for a new record even when I open the form with data in it. I call this sub from the Form OnCurrent event. Any ideas? TIA bwilkens

Sub SaveMain(f As Form, TempTable As String)
Dim DB As Database: Set DB = CurrentDb()
Dim FormRS As DAO.Recordset, TempRS As DAO.Recordset
Dim i As Integer

On Error GoTo Err_SaveMain

' Clear temp table
DB.Execute "Delete * From [" & TempTable & "];"

' Open temp table
Set TempRS = DB.OpenRecordset(TempTable, DB_OPEN_TABLE)
If Err Then
Beep: MsgBox "BUG: " & Error, 48
Exit Sub
End If

' Get Mainform recordset
Set FormRS = f.RecordsetClone



' Find current record in mainform recordset
On Error Resume Next
If f.Bookmark = "" Then Exit Sub
FormRS.Bookmark = f.Bookmark

' If error, we must be at a new record. Exit, since nothing to save.
If Err Then Exit Sub

'
' Create a copy of the main form record in the temp table
'

On Error GoTo Err_SaveMain

' Create a new record
TempRS.AddNew

' Loop through the fields in the new temp table
' .. record, copying into each the mainform field value.
For i = 0 To TempRS.Fields.Count - 1
TempRS(i) = FormRS(TempRS(i).Name)
Next i

' Save the new record
TempRS.Update

Bye_SaveMain:
Exit Sub

Err_SaveMain:
Beep
MsgBox "BUG: " & Error, 48
Resume Bye_SaveMain

End Sub
 
In case anyone is interested, I found the problem - a bookmark always equals "" - you have to use the on error to see if it is set. I removed the line If f.Bookmark = "" Then Exit Sub and the routine worked. Also the code was a sample from the Northwind database - works well for multiple forms undo.
bwilkens
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top