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

Updating a list box

P: n/a
I have a form (Form A) with a list box. Underneath the list box is a
command button that minimizes Form A and opens up Form B. When the
user is done with Form B, its exit button selects the minimized Form A
and closes Form B.

The list box on Form A is to display the records that are either
present or were added via Form B. However, I can't get Form A to
update the list box with the new records via VBA after I close Form B.
If I manually reload Form A, the list box is populated correctly. What
is the best way to update the list box?

Here is the code I am using to set the list box when Form A loads. I
have tried calling this on Form A's focus event, requery, after
update, etc. Thanks in advance for the help.

On Error GoTo e
Dim strSQL As String

'Set the form's filter.
Me.Form.RecordSource = strFilter

'Build the SQL string for the Failures list box.
strSQL = "SELECT [txtRMANumber], [chrFailureCategory],
[memFailureDescription] " & _
"FROM tblParetoFailures " & _
"WHERE [txtRMANumber]= """ & Me![RMA #] & """"

'Determine if this RMA has corresponding failures in the Pareto
table _
'and set the list box's row source as necessary.
If strSQL = "" Then
Me.lstFailures.RowSource = ""
Else
Me.lstFailures.RowSource = strSQL
End If
strSQL = ""

Exit Sub
e: MsgBox Err.Description
Oct 2 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
tr******@comcast.net wrote:
I have a form (Form A) with a list box. Underneath the list box is a
command button that minimizes Form A and opens up Form B. When the
user is done with Form B, its exit button selects the minimized Form A
and closes Form B.

The list box on Form A is to display the records that are either
present or were added via Form B. However, I can't get Form A to
update the list box with the new records via VBA after I close Form B.
If I manually reload Form A, the list box is populated correctly. What
is the best way to update the list box?

Here is the code I am using to set the list box when Form A loads. I
have tried calling this on Form A's focus event, requery, after
update, etc. Thanks in advance for the help.

On Error GoTo e
Dim strSQL As String

'Set the form's filter.
Me.Form.RecordSource = strFilter

'Build the SQL string for the Failures list box.
strSQL = "SELECT [txtRMANumber], [chrFailureCategory],
[memFailureDescription] " & _
"FROM tblParetoFailures " & _
"WHERE [txtRMANumber]= """ & Me![RMA #] & """"

'Determine if this RMA has corresponding failures in the Pareto
table _
'and set the list box's row source as necessary.
If strSQL = "" Then
Me.lstFailures.RowSource = ""
Else
Me.lstFailures.RowSource = strSQL
End If
strSQL = ""

Exit Sub
e: MsgBox Err.Description
Prior to exiting FormB you could requery the listbox in FormA if FormA
is still open. Or in the OnActivate event of FormA do a requery of the
listbox. You could set a flag in FormA when you call FormB so that in
the OnActivate in FormA only requeries the listbox if you called/opened
FormB.

Stop
http://www.youtube.com/watch?v=JFYzU5U-Ytc

Oct 2 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.