Problem with Selected() and Requery on form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form, Form1, with a listbox, Listbox1.
The rowsource of Form1 is based on what is selected in listbox1.
The AfterUpdate-event of listbox1 requery the form and the selected record
is shown. Works fine.

I have a button to open a dialogform (Form2) for adding new records.
When i close Form2 i requery the listbox1 on Form1 and runs a Loop to select
the new item in the listbox.

Code is like this:

For I = 1 To Forms!frmMain!frmActive.Form!lstBestallare.ListCount - 1
If Forms!frmMain!frmActive.Form!lstBestallare.ItemData(I) = IntNew
Then
Forms!frmMain!frmActive.Form!lstBestallare.Selected(I) = True
Forms!frmMain!frmActive.Form.Requery
End If
Next I

This is also working fine. The new row (record) is in Listbox1 on Form1 and
it is selected.

But I have to click the row to have the new record shown. I want it to
display the new record immediatelly without clicking.
I have tried to requery Form1 but no difference. Anyone have an idea what to
do?
 
If I'm understanding correctly, you want frmMain to be refreshed with the
new information. If so, add a

Forms!frmMain.Requery

(it's kind of confusing that you're referring to Form1 and Form2 in your
question, but frmMain and frmActive in your code!)
 
Sorry, maybe I explaned it a little confusing
Form1 is a subform i frmMain
The right code (in Form2) should be:

For I = 1 To Forms!frmMain!Form1.Form!ListBox1.ListCount - 1
If Forms!frmMain!Form1.Form!ListBox1.ItemData(I) = IntNew Then
Forms!frmMain!Form1.Form!ListBox1.Selected(I) = True
Forms!frmMain!Form1.Form.Requery
DoCmd.Close
End If
Next I

The right row in Forms!frmMain!Form1.Form!ListBox1 is selected but when I
try to requery the Forms!frmMain!Form1.Form.Requery nothing happens. I must
click the selected row to se the record.

Thomas


"Douglas J. Steele" skrev:
 
I have solved the problem.
The listbox was placed in the formHeader. Whan I moved it to the detail
section works anything as I wanted. Confusing, but it works!

Thank you for your assistance.
/Thomas

"Douglas J. Steele" skrev:
 
Back
Top