I have an MS Access 2007 database that I ported from MS Access 2003 to 2007 a few years ago. I have been trying to fix a VBA bug ever since I ported this database to 2007 and I finally decided to try asking for help...
My issue occurs when I open one form from another. "Form A" contains a combo-box control with a recordID. When I double click on the combo-box I run a function that is supposed to open a second form, "Form B", and find the appropriate record. In Access 2003 everything worked just fine. When I ported to 2007 I started having issues and they are different depending on whether or not Form B is already open.
If Form B is not open my code will open the form then not complete the rest of the function. If the Form B is already open it will sometimes complete the rest of the code and sometimes not complete it.
Here is my code:
...
DoCmd.OpenForm "Company Entry" ' Form B
' Code always executes to here
' From here it sometimes works and sometimes doesn't
msgbox "Got here?"
DoCmd.SelectObject acForm, "Company Entry"
DoCmd.GoToControl "[CompanyIDText]"
DoCmd.FindRecord lRecordID, acAnywhere, False, , False, acCurrent, True
...
There is nothing unusual in this code and I know it should work just fine. What seems to be happening is, Form B opens but the "focus" (not sure if this the exact term) either remains with Form A or switches back to Form A after Form B is opened so the code can't complete on Form B.
I'm suspecting a bug in Access but I thought I'd better ask to see if I'm missing something. I've been writing code in Access for years so I'm pretty knowledgeable but this one has me stumped. Writing Access code is not my main function at work but I do know quite a bit about Access and VBA (obviously not everything). Can anyone help? I've spent hours on this and I'd hate to go back and write a macro to see if that works but I don't know what else to do here.