473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Listbox doesn't requery after adding a new record

Hi,
I have a mainform, and a subform in it. The main form contains current event details. The subform has ListBox control which contains assignments of that event. To add a new assignment, you click on button and another form opens. The thing is, if the listbox already contains some assignments, the new one are added and shown without a problem. But if the listbox is still empty and i'm adding a first, it doesn't requery, only if i exit the form and reload it. I would really appreciate if someone could point me to the solution.
Here's the code behind the "add new assignment" button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnNewAssignment_Click()
  2. Text = Forms(Parent.Name).Controls("eventNum")
  3. strRow = ListAssignments.ListIndex + 1
  4. strAssignNum = Nz(ListAssignments.Column(7))
  5.     DoCmd.OpenForm "frmNewAssignment", , , , acFormAdd, acDialog, 1 & ";" & Text
  6.     ListAssignments.Requery
  7. End Sub
Aug 11 '10 #1
7 2243
jimatqsi
1,271 Expert 1GB
I don't see how line 6 .Requery does anything for you. The form frmNewAssignment has just been opened but there has not been time for that to be filled out yet when line 6 is executed.

I would add some code to the frmNewAssignment form so that it requeries the listbox on the original form every time it adds a new record.

Jim
Aug 11 '10 #2
Jim, line 6 executes only after the frmNewAssignment has finished all his code, meaning upon return from frmNewAssignment to frmAssignments, and the record is supposed to already exist, so i don't really understand why requery doesn't help.
Aug 11 '10 #3
jimatqsi
1,271 Expert 1GB
No, I don't think that's how it works. There is no "return from frmNewAssignment"; the form is opened and might stay open forever and a day. If he wants his code to wait for that form to do something he needs to add a loop with DoEvents and keep looping until some signal is received.

Jim
Aug 11 '10 #4
Jim, thanks for your help, but i solved this one
Aug 12 '10 #5
NeoPa
32,556 Expert Mod 16PB
Jim is right. The code for Form_Load & Form_Open would run if there were any, before returning to execute line #6. However, any code triggered by an operator interacting with the new form would not cause the succeeding code here to wait, nor indeed would it wait for the form to close. Line #6 is effectively run extremely soon after the opening of the form specifically.

Generally, the Requery call is done from code in an event procedure of the newly opened form after the process of adding the new record has been completed.

You say you have a solution. It might be interesting to see it (not simply for our curiosity, but also for anyone searching around for a solution to a similar problem).
Aug 12 '10 #6
I figured the solution would be interesting to see, but it has to do with my program specifically, so it wont help anyone i think. Anyway, the listbox is inside frmAssignments, which is the subform of frmEvents. In order for it to display the right assignments, it should get current event number. The problem was with the event num variable, it wasn't correct, so it always requeried some other events and not the current. I simply fixed the listbox's row source.
Aug 12 '10 #7
NeoPa
32,556 Expert Mod 16PB
Never mind then :)

Hopefully there is still some interesting info here for any searchers that happen upon this thread.
Aug 12 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Kyralessa | last post by:
In Access 2000, I have a base form with a ListBox of conference registrants. In the form's declarations section I include Dim f as Form To add a registrant I'm doing this: Set f = New...
2
by: Joshua Ammann | last post by:
How do you change what row is highlighted in a listbox (so that it highlights the current record you are viewing in the form) when you use the built-in navagation buttons (or any method other than...
9
by: Greg | last post by:
Binding Manager & dataset - won't add record I've got an untyped dataset with controls bound through code. The user can select a question number from a bound combobox, and the question number and...
6
by: Mark | last post by:
Hello. I have a listbox whose rowsource is set to a saved query (call it "qry_customer_list.") When I add customers to my database, I call the listbox Requery method so that the listbox will...
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
7
by: mr.nimz | last post by:
hello, this is antenio. recently i've come to a problem. i got a way through it, somehow, still it left me in a curious state, so i'm posting it here, if i can get an answer from some techy, ...
1
by: Steve | last post by:
This may be a dumb questions please forgive I have a form that shows a list box that links to a table with 7 employee names The form does not show employee key. When adding record to master...
1
by: Dan2kx | last post by:
Hello, second problem of the day... I have a listbox that is requeried and would like to select the same rows again after that requery.. easy right... Me.lst1.Requery sArray =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.