Solved Button on one form selects listbox item on another (1 Viewer)

mebdrew

New member
Local time
Today, 18:09
Joined
May 28, 2020
Messages
5
I have two forms in question. FrmNewCase is where our admin enters a new case. FrmAllTracker is where several list boxes are referenced, which include New Cases, Case Under Review etc. When she enters a new case on FrmNewCase and hits save, I want FrmAllTracker (which is often already open) to get focused and automatically select the new case from the NewCase list box. I have the setfocus VBA down, but I can't seem to get the VBA to select the listbox. I get the "Object Required" error. Here's what I have (this was just a test button, it's not the button I'll really be using)

Private Sub Command25_Click()
Forms!FrmAllTracker.SetFocus
Forms!FrmAllTracker.Requery
Forms!FrmAllTracker.NewCaseList.Selected(NewCaseList.ListCount - 1) = True
End Sub

Any help or suggestions, maybe OpenArgs? But I'm wayy to unfamiliar with that to use it correctly (tried DoCommand..... , , , , , , , NewCaselist... and poop)

THANK YOU!!!
 

Ranman256

Well-known member
Local time
Today, 18:09
Joined
Apr 9, 2015
Messages
4,339
'refresh the listbox 1st, then try:

vNewNum = me.NewNum
Forms!FrmAllTracker!lstBox.requery
Forms!FrmAllTracker.lstBox = lstBox(vNewNum)
 

mebdrew

New member
Local time
Today, 18:09
Joined
May 28, 2020
Messages
5
'refresh the listbox 1st, then try:

vNewNum = me.NewNum
Forms!FrmAllTracker!lstBox.requery
Forms!FrmAllTracker.lstBox = lstBox(vNewNum)
I used this code (COEMR is one of the fields)
I assumed I needed to declare vNewNum unless that's a function I'm now aware of?

Private Sub Command81_Click()
Dim vNewNum As Integer
vNewNum = Me.COEMR
Forms!FrmAllTracker!NewCaseList.Requery
Forms!FrmAllTracker.NewCaseList = NewCaseList(vNewNum)
End Sub

When I run that I get "Compile Error Sub or Function not defined"

What am I missing?
 

bastanu

AWF VIP
Local time
Today, 15:09
Joined
Apr 13, 2010
Messages
1,402
Is the bound column of the listbox the one storing the case numbers (COEMR in the first form)? If yes you should try:
Code:
Forms!FrmAllTracker!NewCaseList.Requery
Forms!FrmAllTracker.NewCaseList =Me.COEMR

Cheers,
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:09
Joined
Feb 19, 2002
Messages
43,233
@mebdrew You decided on a solution and asked us how to implement it but there is a better solution.
If the form you are opening might already be open, close the form so you can open it fresh with a where argument to go to the correct record. Keep in mind that this will save any dirty record in the process of being updated and that leads us to -

But an even better solution is to not allow users to keep multiple forms open at the same time since this tends to lead to confusion and errors. I imagine that there might be some customer interface app where you are so busy, you need to try to do multiple things simultaneously so I won't say to never keep multiple forms only. Just seriously consider closing them or providing a way on the open form to select a different record instead of having to go back to the calling form.
 

mebdrew

New member
Local time
Today, 18:09
Joined
May 28, 2020
Messages
5
That worked wonderfully! The listbox also searches for a record, but I have that part down. I can't believe this was so simple! THANK YOU!!!
 

mebdrew

New member
Local time
Today, 18:09
Joined
May 28, 2020
Messages
5
@mebdrew You decided on a solution and asked us how to implement it but there is a better solution.
If the form you are opening might already be open, close the form so you can open it fresh with a where argument to go to the correct record. Keep in mind that this will save any dirty record in the process of being updated and that leads us to -

But an even better solution is to not allow users to keep multiple forms open at the same time since this tends to lead to confusion and errors. I imagine that there might be some customer interface app where you are so busy, you need to try to do multiple things simultaneously so I won't say to never keep multiple forms only. Just seriously consider closing them or providing a way on the open form to select a different record instead of having to go back to the calling form.
I am not a fan of multiple forms being open for a variety of reasons. In this case, the New Case form is rare to be opened, the form I am updating is the master view, which handles a vast, vast majority of functions (and the functions it doesn't handle do not interact with the master view). Thanks so much for the input, and validating my disdain for multiple open forms.
 

Users who are viewing this thread

Top Bottom