Saving current row on Form exit

A

aine_canby

Hello again,

I wish to save the current row on a form so that it can be
automatically selected the next time the form is opened. To do this, I
have the following -

'save the current row
Private Sub Form_Close()
SQLString = " DELETE * FROM tblPreviousFormState;"
CurrentDb.Execute SQLString, dbFailOnError

SQLString = "INSERT INTO tblPreviousFormState(TableID) Values(" &
TableID & ");"
CurrentDb.Execute SQLString, dbFailOnError
End Sub

I'm sure there is some nice way of having a one row table but I'm not
sure about this...

TableID is the name of my text box where the row primary key is
displayed. The issue though is that TableID is always returning the
value 1 in Form_Close - I guess the control has been destroy to some
extent at this point. Anyway, I'm not sure if the above approach is a
good one anyway. Can any offer me a solution to this problem?

BTW, heres how I set the current row -

Private Sub Form_Open(Cancel As Integer)

'get the previous row
Dim recordSetPreviousFormState As DAO.Recordset
Set recordSetPreviousFormState = CurrentDb.OpenRecordset("Select *
from tblPreviousFormState")

If recordSetPreviousFormState.RecordCount <> 0 Then
recordSetPreviousFormState.MoveFirst
Me.Recordset.FindFirst "TableID= " &
recordSetPreviousFormState.Fields("TableID")
End If

End Sub


Thanks again,

Aine.
 
A

aine_canby

Hello again,

I wish to save the current row on a form so that it can be
automatically selected the next time the form is opened. To do this, I
have the following -

'save the current row
Private Sub Form_Close()
SQLString = " DELETE * FROM tblPreviousFormState;"
CurrentDb.Execute SQLString, dbFailOnError

SQLString = "INSERT INTO tblPreviousFormState(TableID) Values(" &
TableID & ");"
CurrentDb.Execute SQLString, dbFailOnError
End Sub

I'm sure there is some nice way of having a one row table but I'm not
sure about this...

TableID is the name of my text box where the row primary key is
displayed. The issue though is that TableID is always returning the
value 1 in Form_Close - I guess the control has been destroy to some
extent at this point. Anyway, I'm not sure if the above approach is a
good one anyway. Can any offer me a solution to this problem?

BTW, heres how I set the current row -

Private Sub Form_Open(Cancel As Integer)

'get the previous row
Dim recordSetPreviousFormState As DAO.Recordset
Set recordSetPreviousFormState = CurrentDb.OpenRecordset("Select *
from tblPreviousFormState")

If recordSetPreviousFormState.RecordCount <> 0 Then
recordSetPreviousFormState.MoveFirst
Me.Recordset.FindFirst "TableID= " &
recordSetPreviousFormState.Fields("TableID")
End If

End Sub

Thanks again,

Aine.

Has anyone any suggestions for me on this one?

Thank you,

Aine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top