Refreshing data in a list

F

freedomverse

I have a supposedly easy question but I am having trouble with the answer.

I have a sub form named "songsdetail" that has a button that opens the
"song" form so that I can add new songs to the song list. This works great.
When I return to the "songsdetail" form the new song doesn't show up in the
combo box "SongTitle" until I press F9 or the "refresh all" button. Is there
a way to make it update the list automatically? I must be misunderstanding
something in the help file as I have had no success.

Cheers,
Jared.
 
M

Marshall Barton

freedomverse said:
I have a supposedly easy question but I am having trouble with the answer.

I have a sub form named "songsdetail" that has a button that opens the
"song" form so that I can add new songs to the song list. This works great.
When I return to the "songsdetail" form the new song doesn't show up in the
combo box "SongTitle" until I press F9 or the "refresh all" button. Is there
a way to make it update the list automatically?


You can Requery the combo box after the song form closes.
Assimung you open that form in dialog mode, the next line
would be:
Me.SongTitle.Requery
 
F

freedomverse

Thank you. Where do I enter that line, Me.SongTitle.Requery? I had tried
something similar in visual basic in the "on got focus" -- but this doesn't
seem to be the correct place.

Thanks,
Jared.
 
M

Marshall Barton

As I said before:

"Assuming you open that form in dialog mode,
"the next line [after OpenForm] would be:
" Me.SongTitle.Requery

A less desirable, but also reliable, place to requery would
be in the other form's Close event. Wihle this would be
necessary if you do not open that form in dialog mode, it is
undesirable because it makes the other form dependent on the
structure of your main form and subform:
Forms!yourmainform.songsdetail.Form.SongTitle.Requery

If you are not familiar with dialog mode, check VBA Help on
OpenForm
 
F

freedomverse

I tried putting the code you recommended:

Me.SongTitle.Requery

It gave me an error and opened the debugger. I placed the command on it's
own line after the openform line and I also tried to put it after the
gotorecord line.

Basically the "Command96" button is the one that opens the "Song" form.
There I add a new song and close that form. When I get back my main form I
want the combo box to requery so that it will include the new song that I
have just entered.

Here is my code:

Private Sub Command96_Click()
On Error GoTo Command96_Click_Err

DoCmd.OpenForm "Song"
DoCmd.GoToRecord , "", acNewRec


Command96_Click_Exit:
Exit Sub

Command96_Click_Err:
MsgBox Error$
Resume Command96_Click_Exit
 
M

Marshall Barton

freedomverse said:
I tried putting the code you recommended:

Me.SongTitle.Requery

It gave me an error and opened the debugger. I placed the command on it's
own line after the openform line and I also tried to put it after the
gotorecord line.

Basically the "Command96" button is the one that opens the "Song" form.
There I add a new song and close that form. When I get back my main form I
want the combo box to requery so that it will include the new song that I
have just entered.

Here is my code:

Private Sub Command96_Click()
On Error GoTo Command96_Click_Err

DoCmd.OpenForm "Song"
DoCmd.GoToRecord , "", acNewRec


You ***must*** open the Song form in Dialog mode!

DoCmd.OpenForm "Song", WindowMode:=acDialog
Me.SongTitle.Requery
DoCmd.GoToRecord , "", acNewRec

You really should use VBA Help on any statement you do not
understand completely. Not having a good understanding what
your (even wizard created) code is doing will often going to
lead to the kind of problems you are having now and it's
costing you days of delay in reaching a resolution.
 
F

freedomverse

I realize that I wouldn't last a day in the 'real world' doing this sort of
stuff but when working on a project for your church you find yourself wearing
hats that you may not have ever known existed. So, yes, I am uneducated and
have learned access mostly by the "dummies" book and the access help file. I
have put together a pretty cool database so far without the need of any
knowledge of 'code' but to do these final touches I find myself needing to
know a bit. I could be 'done' without them but with them it will be a much
more user friendly database. I will be on my way to the store / or library
soon to get a book about Visual Basic but until then.... back to my issue at
hand:

When I put in the code you recommended I get a compile error on the
Me.SongTitle.Requery line. Taking this line out removes the error but makes
another problem: The "Song" from no longer goes to a new record and upon
return to the main form IT goes to a new record, no good. I have spent an
hour trying to find out how to write the code more specifically so that I get
what I want but so far am still stuck. In short, here is what I want:

1. Pressing the button (located on the subform called "SongsDetail") would
bring me to the "Songs" form and display a new record.
2. There I can enter a new song in the list and close that form.
3. Upon Returning to the main form I want the field called "SongTitle" that
is located in the subform "SongsDetail" to include the new song that I just
entered
4. I want to then smile because it all works great!

I do very much appreciate your help if you are still willing to put up with
my inexperience.

Regards,
Jared.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top