Avatar of Jenkins
JenkinsFlag for United States of America

asked on 

combobox and subform problem

I have a combobox on a main form.  
The main form does not have a record source.
The record source of the combobox is a table.

I have a subform on the main form. The subform's record source
is a table (different from the one tied to the combobox).
I have a textbox in the header section of the subform.
I want to set its value to whatever the combobox's value is.
If the combobox value changes, I want the textbox value on the subform
to change.

Below is what I already have under the After Update event of the combobox.
What is going on is when a combobox selection is made, the table tied
to the subform is cleared and then populated with data related to whatever
the combobox selection is.  


Private Sub MyComboBox_AfterUpdate()

With DoCmd
   .SetWarnings False
   .Hourglass True
   .OpenQuery "DeleteTemporaryTable"
   .OpenQuery "PopulateTemporaryTable"
   .SetWarnings True
   .Hourglass False
End With
   
   Me!MySubform.Form.Requery


Adding this code to the AferUpdate event (I've tried placing it in different
sections of the code) is causing a 440 run-time error:

 Me.MySubform.Form.MyTextbox = Me.MyComboBox

What's the problem?   Thanks.
Microsoft Access

Avatar of undefined
Last Comment
Jenkins
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of dqmq
dqmq
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Jenkins
Jenkins
Flag of United States of America image

ASKER

OK, here's another thing that's happening.  I'll go step by step in plain English.

I open the form.  the combobox as well as the subform will already be properly populated with records.

I select a different value in the combobox.  I get a pop-up window: "Run-time error '3167' Record is deleted"

At that point, all records/textboxes, etc in the subform display: #Deleted

I click 'End' in the pop-up window. That closes the pop-up window. Everything in the subform still displays as #Deleted.

I change the combobox value.  The subform is properly populated with records.

I change the combobox value again.  I get the '3167' error message again and everything displays as #Deleted.

I change the combobox value again.  The subform is properly populated.

So there's a pattern.  Every other time I change the combobox value, I get the error message.
This is with me having the following as the very last line of code in the combobox's After Update event:

 Me.MySubform.Form.MyTextBox = Me.MyComboBox
Avatar of Jenkins
Jenkins
Flag of United States of America image

ASKER

Don't ask me why because I'm an idiot but I got the thing to work by coding the following line twice:

Me!MySubform.Form.Requery
------------------------------------------------------------------------------------------
So, the entire After Update Event looks like this:

Private Sub MyComboBox_AfterUpdate()

With DoCmd
   .SetWarnings False
   .Hourglass True
   .OpenQuery "DeleteTemporaryTable"
   .OpenQuery "PopulateTemporaryTable"
   .SetWarnings True
   .Hourglass False
End With
   
   Me!MySubform.Form.Requery
   Me.MySubform.Form.MyTextbox = Me.MyComboBox
   Me!MySubform.Form.Requery

As long as I require twice, I don't get any errors.  Weird.


Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo