By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,705 Members | 1,852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,705 IT Pros & Developers. It's quick & easy.

Position a list to a record?

P: n/a
When I activate frmList.List0, it positions at the end of the table:
- frmList
Private Sub Form_Activate()
Me.List0.SetFocus
Me.List0.ListIndex = Me.List0.ListCount - 1
-

When I DblClick a row in frmList.List0, I close frmList and open frmEdit to
edit record I clicked on:
-frmList
Private Sub List0_DblClick(Cancel As Integer)
Dim strWhere As String
strWhere = "WPS = " & Me.List0.Value
Zindex = Me.List0.ListIndex 'can Zindex somehow be used to reposition
when I activate next time?
DoCmd.Close
DoCmd.OpenForm "frmEdit", , , strWhere
End Sub
-

After I edit the record I exit frmEdit and activate frmList again:
-frmEdit
Private Sub cmdExit_Click()
DoCmd.Close
DoCmd.OpenForm "frmList"
End Sub
-

How can I return to frmList and have List0 positioned at the record I was on
when I DblClicked?

I tried changing the frmList activate event to:
-frmList
Private Sub Form_Activate()
Me.List0.SetFocus
If Not IsNull(Zindex) Then
Me.List0.ListIndex = Me.List0.ListCount - 1
Else
Me.List0.ListIndex = Zindex
End If
-

But this is not working.

Please help
Bill
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Just don't close frmList - the selection indicator will remain on the
last selected item. Get rid of the Form_Activate - 'cuz it puts the
selection indicator at the bottom of the list everytime the form is
activated. If you don't close frmList you could put the code for
Form_Activate in the Form_Open event - then the selection indicator
won't always move to the bottom of the list when frmList is re
activated.

If you really don't want to do it my way - change the frmList's
Form_Activate routine. (I'm assuming that the variable Zindex is a
global variable.)

Private Sub Form_Activate()
Me!List0.SetFocus
If Zindex = 0 Then
Me!List0.ListIndex = Me!List0.ListCount - 1
Else
Me!List0.ListIndex = Zindex
End If
End Sub

HTH,

MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP5cNDIechKqOuFEgEQKQpACfdjx0GgWbz4roAlkpyTTygR v/HX8AnRXj
f/bQ/kwz0e0HE1/qVlLqnbzq
=Rzhk
-----END PGP SIGNATURE-----

BillB wrote:
When I activate frmList.List0, it positions at the end of the table:
- frmList
Private Sub Form_Activate()
Me.List0.SetFocus
Me.List0.ListIndex = Me.List0.ListCount - 1
-

When I DblClick a row in frmList.List0, I close frmList and open frmEdit to
edit record I clicked on:
-frmList
Private Sub List0_DblClick(Cancel As Integer)
Dim strWhere As String
strWhere = "WPS = " & Me.List0.Value
Zindex = Me.List0.ListIndex 'can Zindex somehow be used to reposition
when I activate next time?
DoCmd.Close
DoCmd.OpenForm "frmEdit", , , strWhere
End Sub
-

After I edit the record I exit frmEdit and activate frmList again:
-frmEdit
Private Sub cmdExit_Click()
DoCmd.Close
DoCmd.OpenForm "frmList"
End Sub
-

How can I return to frmList and have List0 positioned at the record I was on
when I DblClicked?

I tried changing the frmList activate event to:
-frmList
Private Sub Form_Activate()
Me.List0.SetFocus
If Not IsNull(Zindex) Then
Me.List0.ListIndex = Me.List0.ListCount - 1
Else
Me.List0.ListIndex = Zindex
End If
-

But this is not working.

Please help
Bill


Nov 12 '05 #2

P: n/a

"MGFoster" <me@privacy.com> wrote in message
news:92*****************@newsread3.news.pas.earthl ink.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Just don't close frmList - the selection indicator will remain on the
last selected item. Get rid of the Form_Activate - 'cuz it puts the
selection indicator at the bottom of the list everytime the form is
activated. If you don't close frmList you could put the code for
Form_Activate in the Form_Open event - then the selection indicator
won't always move to the bottom of the list when frmList is re
activated.
Thanks MG,
That was too easy!!

I had already tried what you said below using Zindex, but could not get that
to work. I think my problem with that method is that I am not sure how to
define a globle variable. I know many people here do not like to use them,
but I want to know why it didn't work.
I put this statement:
Public Zindex As Integer
at the top of the code in the form module (general declarations ). I also
tried it in Module1. When a form closed the value of Zindex showed in the
watch window as out of context. Am I missing something about defining a
global variable?

Bill
If you really don't want to do it my way - change the frmList's
Form_Activate routine. (I'm assuming that the variable Zindex is a
global variable.)

Private Sub Form_Activate()
Me!List0.SetFocus
If Zindex = 0 Then
Me!List0.ListIndex = Me!List0.ListCount - 1
Else
Me!List0.ListIndex = Zindex
End If
End Sub

HTH,

MGFoster:::mgf
Oakland, CA (USA)

I already had tried that second way.
Nov 12 '05 #3

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Try this definition in the Description section of a standard module:

Global ZIndex As Integer

If you put a variable definition in the Description section of a form
module it is only a module variable - its scope is the form.
Everytime the form closes the variable goes out of scope.

- --
MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP5hZE4echKqOuFEgEQJULgCgxKEXLOJJM9wFkYKsQf3mbX I2RrsAoPef
pSLbEkot/IOPJhqtZIQYAFaH
=6kPn
-----END PGP SIGNATURE-----

BillB wrote:
"MGFoster" <me@privacy.com> wrote in message
news:92*****************@newsread3.news.pas.earthl ink.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Just don't close frmList - the selection indicator will remain on the
last selected item. Get rid of the Form_Activate - 'cuz it puts the
selection indicator at the bottom of the list everytime the form is
activated. If you don't close frmList you could put the code for
Form_Activate in the Form_Open event - then the selection indicator
won't always move to the bottom of the list when frmList is re
activated.

Thanks MG,
That was too easy!!

I had already tried what you said below using Zindex, but could not get that
to work. I think my problem with that method is that I am not sure how to
define a globle variable. I know many people here do not like to use them,
but I want to know why it didn't work.
I put this statement:
Public Zindex As Integer
at the top of the code in the form module (general declarations ). I also
tried it in Module1. When a form closed the value of Zindex showed in the
watch window as out of context. Am I missing something about defining a
global variable?

Bill

If you really don't want to do it my way - change the frmList's
Form_Activate routine. (I'm assuming that the variable Zindex is a
global variable.)

Private Sub Form_Activate()
Me!List0.SetFocus
If Zindex = 0 Then
Me!List0.ListIndex = Me!List0.ListCount - 1
Else
Me!List0.ListIndex = Zindex
End If
End Sub

HTH,

MGFoster:::mgf
Oakland, CA (USA)


I already had tried that second way.


Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.