A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Saving current row on Form exit



 
 
Thread Tools Display Modes
  #1  
Old May 31st, 2007, 11:51 AM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 15
Default Saving current row on Form exit

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.

  #2  
Old May 31st, 2007, 01:02 PM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Saving current row on Form exit

Try using Form_Unload instead of Form_Close.

The approach you have should work. Here's a slightly different way to
approach the same thing:
Return to the same record next time form is opened
at:
http://allenbrowne.com/ser-18.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

wrote in message
ps.com...
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.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:02 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.