Search ComboBox not Working (1 Viewer)

Tupacmoche

Registered User.
Local time
Today, 04:55
Joined
Apr 28, 2008
Messages
291
Hi Form Masters,

I have a combobox created with the Access wizard that works fine except when, I add a new record to the table. Here is the code:
Code:
Private Sub CboFind_AfterUpdate()
On Error GoTo CboFind_AfterUpdate_Err

    DoCmd.SearchForRecord , "", acFirst, "[Upload_Number] = " & Str(Nz(Screen.ActiveControl, 0))

CboFind_AfterUpdate_Exit:
    Exit Sub

CboFind_AfterUpdate_Err:
    MsgBox Error$
    Resume CboFind_AfterUpdate_Exit
 End Sub
I have a sproc that adds a row to the table that is linked (SQL 2008 rs) this works fine and is not the issue since the records are always added. The issue is that when I try to select the new record from the combbox a different row is selected. This doesn't effect existing records. But if I restart the application then there is no issue it selects the new record. Clearly, I don't want user to have to restart the application every time they add a new row. Has anyone encountered this issue and know how to fix it?:confused:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:55
Joined
Oct 29, 2018
Messages
21,477
Hi. Just before the DoCmd.SearchRecord line, try adding this:
Code:
Me.Requery
Hope it helps...
 

Tupacmoche

Registered User.
Local time
Today, 04:55
Joined
Apr 28, 2008
Messages
291
I did and now the combo search box dosn't work at all. I removed it.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:55
Joined
Oct 29, 2018
Messages
21,477
I did and now the combo search box dosn't work at all. I removed it.
Hi. What does "doesn't work" mean? Were you getting any errors? Are you able to post a small copy of your db with test data?
 

Tupacmoche

Registered User.
Local time
Today, 04:55
Joined
Apr 28, 2008
Messages
291
What, I mean is that after adding Me.Requery before DoCmd.SearchRecord line when I used the combobox to select a name from it it did not change the row. Basically, it did nothing.:eek:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:55
Joined
Oct 29, 2018
Messages
21,477
What, I mean is that after adding Me.Requery before DoCmd.SearchRecord line when I used the combobox to select a name from it it did not change the row. Basically, it did nothing.:eek:
Hi. One way to know for sure what is or is not happening is to step through the code. Are you able to do that? If not, are you able to post a copy of your db, so we can try to do it for you?
 

Tupacmoche

Registered User.
Local time
Today, 04:55
Joined
Apr 28, 2008
Messages
291
I have been googling to find a solution since my post. On the Home Ribbon -> Refresh All works after I add a new row. So, now, I'm need to know what vba command does Refresh All launch so, I can run it from vba. Any ideas?:mad:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:55
Joined
Oct 29, 2018
Messages
21,477
I have been googling to find a solution since my post. On the Home Ribbon -> Refresh All works after I add a new row. So, now, I'm need to know what vba command does Refresh All launch so, I can run it from vba. Any ideas?:mad:
Well, either Me.Refresh or Me.Requery should do the same thing. That's why I recommended it. See if there's a DoCmd equivalent, like maybe DoCmd.Refresh or maybe DoCmd.RunCommand acCmdRefreshAll, or something like that. Cheers!
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:55
Joined
Feb 19, 2013
Messages
16,619
Sounds like your combo is not being requeried - how is it populated? Or perhaps the activecontol is not what you thinking
 

Tupacmoche

Registered User.
Local time
Today, 04:55
Joined
Apr 28, 2008
Messages
291
Hi All,

Finally found the solution. This is the web site that had it:
Code:
 [URL="http://www.accessforums.net/showthread.php?t=33098"]http:[/URL][URL="http://www.accessforums.net/showthread.php?t=33098"]//www.accessforums.net/showthread.php?t=33098[/URL]
As, I mentioned earlier when I clicked on 'Refresh All' from the home menu the combobox worked fine. So, I added this line to the AfterUpdate code textbox that is used to add new records:
Code:
CommandBars.ExecuteMso "DataRefreshAll"
Now, when, I select the newly added record it works just fine. :D
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:55
Joined
Oct 29, 2018
Messages
21,477
Hi All,

Finally found the solution. This is the web site that had it:
Code:
 [URL="http://www.accessforums.net/showthread.php?t=33098"]http:[/URL][URL="http://www.accessforums.net/showthread.php?t=33098"]//www.accessforums.net/showthread.php?t=33098[/URL]
As, I mentioned earlier when I clicked on 'Refresh All' from the home menu the combobox worked fine. So, I added this line to the AfterUpdate code textbox that is used to add new records:
Code:
CommandBars.ExecuteMso "DataRefreshAll"
Now, when, I select the newly added record it works just fine. :D
Hi. Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom