Listbox VB selection locks form

carlnewton

Registered User.
Local time
Yesterday, 19:00
Joined
Jan 10, 2008
Messages
19
I'm simply trying to select an item in a bound listbox. When I do this, the form locks up. I added a setfocus to an unbound button and that generated Reserved Error 2950. Stumped again.

Dim lg As Long, lgIndex As Long, lgLastUser As Long

With Me

lgLastUser = Val(!LastUser.Caption)
DoCmd.RunCommand acCmdAppMaximize
DoCmd.Restore

' do this routine to select the last front-end user
If Not Nz(!LastUser.Caption, "") = "" Then

With !unbUsername
lgIndex = .ListCount
Do Until lgIndex = -1
If .ItemData(lgIndex) = lgLastUser Then
.Selected(lgIndex) = True
Exit Do
End If
lgIndex = lgIndex - 1
Loop
End With

End If

!btnLogin.SetFocus

End With

Suggestions?
 
Last edited:
Instead of
Code:
If .ItemData(lgIndex) = lgLastUser Then
.Selected(lgIndex) = True
Exit Do
End If
Have you tried
Code:
If .ItemData(lgIndex) = lgLastUser Then
.value = .itemdata(lgIndex) 
Exit Do
End If
Just a thought . . .
 
That Worked! Thanks much.

One more question:

I'm trying to store the last user in the caption field of an unbound label. After writing that value, I then save the form. But the value isn't saved. When I restart the DB again it's lost. I'm obviously not understanding the .tag field.

Heres the code:

(unbUsername is the Listbox, !LastUser is the unbound Label)

With Me
If IsNull(!unbUsername) Then Exit Sub

.Visible = False ' leave this form open so that a table will always be open. This will sustain the
' connection for the split database and thereby speed up the application


DoCmd.OpenForm ("Switchboard")

Forms!switchboard!unbUserID = !unbUsername
Forms!switchboard!unbUser = !unbUsername.Column(1)
Forms!switchboard.SetFocus
!LastUser.Caption = !unbUsername.Column(0) ' store this user in the tag field - we'll use it in the Form_Open event
DoCmd.Save acForm, Me.Name ' store the tag field value in the form

End With

Exit Sub

Thanks very much for your help.
 
I'm not sure I quite understand, do you mean
Code:
Forms!switchboard!LastUser.Caption = Forms!swithboard!unbUsername
?
That should work to set the caption (or visible text) in the label to whatever value you have in unbUsername . . .not sure what that has to do with the tag property though . . .
 
Sorry, I confused the issue (that time of day).

Nothing to do with tag. Initally, I was trying to use the Form.Tag field to store the last users identity. But I found that when the form was started in the next session that the Form.Tag field was null. So I've created an unbound label and I'm saving the !lastUser value in the !LastUser.Caption field. But when the form is opened in the next session I get the same result.

This is the line in which I store the Value of the Listbox into the unbound Label (LasterUser.Caption) caption field.

!LastUser.Caption = !unbUsername.Column(0) ' store this user in the tag field - we'll use it in the Form_Open event

Shouldn't the unbound label caption value be saved. Shouldn't I be able to recall the last String written to the caption?

Thanks
 
Did you try Forms!switchboard!LastUser.Caption = Forms!swithboard!unbUsername.ItemData(0)?
 
I gave that a try but didn't work. I've tried everything that I can think of to save a value on the form rather then in a table so that I can recall that value on the local MDE before a recordset is opened. But no matter what I've tried, the Form won't save the value after being shut down. I've even written to the .filter property and tried to use that as a 'container'. I've bound and unbound the form to see if that will affect this performance. No luck. Thanks for your help.
 
If you are sure the code is working (i.e., check that the caption is getting the right value in break mode), but it is just not getting saved, maybe it has something to do with trying to save changes to the design of the form - I think that isn't permitted in an mde?
 
Thats probably it. I've been working with Access for many years (not a programmer) but I've only recently worked with the split database\mde mode of operation. I think that you've explained it. Sometimes the obvious is hard to see. In working with the MDE I don't think that there will be a way to save a modified form. I'll have to let this feature go unless I want to work with a BE table.

Thanks for your guidance.
 

Users who are viewing this thread

Back
Top Bottom