Error with Combo Box (1 Viewer)

AC5FF

Registered User.
Local time
Today, 12:47
Joined
Apr 6, 2004
Messages
552
I've been looking without success for an answer to what is probably a stupid error I am getting. Recently upgraded to Office365 and methods I used with Access 2000 are not working here.

My form has a combo box for a user to select an account number. I want to use that selected account in a query that populates a subform. Another of my databases does the same thing; I used the 'after update' property of the combo box to put in this code:
Code:
Private Sub Combo31_AfterUpdate()
    Me.Text31 = Me.Combo31.Column(0)
    Me.Refresh
End Sub
I am getting a compile error that says "Method or Data Member Not Found" with the highlight on the "Private Sub ...." line

This is exactly how my other database is done and it works there.

I'm likely missing something really basic here - just can't see it.

Thanks!
 

isladogs

MVP / VIP
Local time
Today, 18:47
Joined
Jan 14, 2017
Messages
18,258
Do you have a control called Text31 and if so is it unbound?
 

AC5FF

Registered User.
Local time
Today, 12:47
Joined
Apr 6, 2004
Messages
552
Okay.. Here is where I show how bad of a database guy I am.
I'm great with queries and tables, etc. pretty okay with reports and forms. But I absolutely am terrible with VB.
I was able to get my old database to work - but it's been a few years back and I am not 100% sure what I did to make it work! HA!
 

AC5FF

Registered User.
Local time
Today, 12:47
Joined
Apr 6, 2004
Messages
552
My subform is getting data from this query:
Code:
SELECT TechWorkHistorical.*
FROM TechWorkHistorical
WHERE (((TechWorkHistorical.[Account Number])=[forms]![TechWorkHistorical_Display Select]![text31]));

Not sure if it would help, but thought I would include it here just in case.
 

isladogs

MVP / VIP
Local time
Today, 18:47
Joined
Jan 14, 2017
Messages
18,258
Yes but to repeat do you have a control called Text31 on that form?
If not the me.text31 bit is meaningless as Me. only applies to the form in which the code resides

Replace with the form name used in the query or use a variable to store the value or .... lots of other ways....
 

AC5FF

Registered User.
Local time
Today, 12:47
Joined
Apr 6, 2004
Messages
552
Okay. Trying to do some reading as well as follow what you are saying here...
Do I have a control called Text31 - I think I would say the answer is no.
If I understand 'unbound' correctly - then I would say my combobox is unbound.

I tried to put 'text31' into the control source property field for the combobox but that gives an error when I select something in the combobox - "Control can't be edited - its bound to an unknown field 'Text31'"

So I'm reading (or trying to) figure out how to store the combo box value for later use; just not gotten there yet.
 

AC5FF

Registered User.
Local time
Today, 12:47
Joined
Apr 6, 2004
Messages
552
Update.... Got it semi to work. Knew I was missing something stupid. Didn't need the VB code part (I don't think. That may change here later). Was an issue between my query and the combo box. That's all straightened out.

So issue now becomes updating my form once the selection is made in the combo box. Either "On Click" or "Lost Focus". Right now it does not update. If I make a selection in the combo box I can go run the query and my results are correct. I can open the subform itself to display the results - and that's correct as well. But on my main form, the subform used to display the results never updates.

I may add a button and just put the output to a report. Not sure yet.

Overall - learned a little bit through this process.
 

moke123

AWF VIP
Local time
Today, 13:47
Joined
Jan 11, 2013
Messages
3,935
Do I have a control called Text31 - I think I would say the answer is no.
Code:
SELECT TechWorkHistorical.*
FROM TechWorkHistorical
WHERE (((TechWorkHistorical.[Account Number])=[forms]![TechWorkHistorical_Display Select]![text31]));

you need to have a textbox on your form NAMED Text31, not the control source.
This will work provided your combobox is named Combo31
Code:
Private Sub Combo31_AfterUpdate()
    Me.Text31 = Me.Combo31.Column(0)
    Me.YourSubFormName.Requery
End Sub
also put your subform name in Me.YourSubFormName.Requery
 

moke123

AWF VIP
Local time
Today, 13:47
Joined
Jan 11, 2013
Messages
3,935
on second thought...

Code:
SELECT TechWorkHistorical.*
FROM TechWorkHistorical
WHERE (((TechWorkHistorical.[Account Number])=[forms]![TechWorkHistorical_Display Select]![text31]));

could just as easily be

Code:
SELECT TechWorkHistorical.*
FROM TechWorkHistorical
WHERE (((TechWorkHistorical.[Account Number])=[forms]![TechWorkHistorical_Display Select]![Combo31]));

and

Code:
Private Sub Combo31_AfterUpdate()

     Me.YourSubFormName.Requery

End Sub
 

AC5FF

Registered User.
Local time
Today, 12:47
Joined
Apr 6, 2004
Messages
552
Thanks Moke...

I also found reference to that "Me.SubFormName.Requery" statement
That was a couple days ago (took yesterday off) and I know I had to play around a little bit, but it did end up working for me.

I just need to reformat this subform to make it a little more 'readable' for the end user. Fairly simple task.. :)
 

Users who are viewing this thread

Top Bottom