Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 24th, 2012, 03:46 AM
Registered User
 
Join Date: Jan 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update Text box with Combo box

Hello,

I have a "Properties" field which is a combo box whose dropdown displays 2 columns ("Property List", "Amount") . When selected, only the "Property List" displays and writes to the table. I would like the "Amount" to populate the next text box ("Targeted') automatically.

I've tried to add the AfterUpdate on the Properties field to say Me.Targeted = Me.Properties.Column(1) but this is not working.

Can pls. anybody teach me how to...Thanks

Last edited by nicole05; January 24th, 2012 at 03:48 AM..
 
Old January 24th, 2012, 12:05 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

The After Update event code looks correct.

Would you please give more detail about what happens?

Are there error messages after you enter something in the Properties combobox?

Does Me.Targeted get updated but is not saved to the table? That would indicate the control in not bound to the correct field.


TIP - Access terminology:
Fields are in tables.
Controls are on Forms/Reports.
A control on a Form/Report can be bound to field in the form's/report's record source
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
 
Old January 24th, 2012, 12:26 PM
Registered User
 
Join Date: Jan 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the replied. Yes sir if i click the combo box the value was there on the table but text box("Targeted") was blank.

Combo box name- "Properties"
Control Source of Combo box - "Properties"
Row Source- SELECT [combo].[ID], combo.[Property], [combo].[Amount] FROM combo ORDER BY [Property];
Bound Column-2

After Update code:
Private Sub Properties_AfterUpdate()
Me.Targeted = Me.Properties.Column(1)
End Sub

on the text box "Targeted" where the value suppose to be fill is
Text box name- "Targeted"
Control Source of "Targeted" - "Targeted"
 
Old January 24th, 2012, 12:47 PM
Registered User
 
Join Date: Jan 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is no error messages after i enter on the "Properties" combo box. The value from the "Property List" populate the Properties combo and saved on the table but the "Amount" that should populate the "Targeted" is not save on the table. Where i should bound the control source of "Properties"combo box and "Targeted" text box? Thank you
 
Old January 24th, 2012, 01:30 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

I think I spotted what may be the issue:

Quote:
I have a "Properties" field which is a combo box whose dropdown displays 2 columns ("Property List", "Amount")
What you left out was that there are three column but only two are displayed.

The row source of the combo box is set to:

Code:
SELECT [combo].[ID], combo.[Property], [combo].[Amount] FROM combo ORDER BY [Property];
Column(0): [combo].[ID]
Column(1): combo.[Property]
Column(2): [combo].[Amount]

*Note: The index started counting with 0 not 1.

The combo box has three columns.
I would assume that the first column width is zero (0"). That is why you are only seeing two columns displayed.


The amount is the third column so you would need to use:

Code:
Me.Targeted = Me.Properties.Column(2)
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
 
Old January 25th, 2012, 02:48 AM
Registered User
 
Join Date: Jan 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sir i changed it already to Column(2) but still did not work...Is the combo box "Properties" are the one which is in the after update or the text box "Targeted"? Is the "Targeted" text box and Combo "Properties" were bound to correct control source? i already did what you've given me sir...Maybe again you have some idea on what was really wrong on my database...I thank you really sir.
 
Old January 25th, 2012, 04:08 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

I do want you are trying to do a lot. I know it can work.

I suspect your issue is with the properties of the combo box.

Is the combo box's property ColumnCount set to three?


You said:

Quote:
on the text box "Targeted" where the value suppose to be fill is
Text box name- "Targeted"
Control Source of "Targeted" - "Targeted"
I find it best to change the name of the text box control to NOT match the name of the bound field.e

I would recommend using:

Text box name- "txtTargeted"
Control Source of "Targeted" - "Targeted"



The combo box would use the cbo prefix.


So you would have:

Code:
Private Sub cboProperties_AfterUpdate()
     Me.txtTargeted = Me.cboProperties.Column(2)
End Sub
This assumes that the combo box has three columns in the row source and the ColumnCount property is set to three.
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
 
Old January 26th, 2012, 03:30 AM
Registered User
 
Join Date: Jan 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Good day,

Sir I tried to changed the textbox name to "txtTargted" and Yes, the Column Count is 3.

Private Sub cboProperties_AfterUpdate()
Me.txtTargeted = Me.cboProperties.Column(2)
End Sub

Tried this code too..

Private Sub Properties_AfterUpdate()
Me.txtTargeted = Me.Properties.Column(2)
End Sub

All those 2 codes were not working. Is their is any relation on Data type sir of my combo box? The Data Type of my combo box "Properties" field is set to "Text" and all other Fields are "Currency".Thank you very much sir for the concern.
 
Old January 26th, 2012, 11:35 AM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

As a test try this:

Code:
Private Sub Properties_AfterUpdate()

     Msgbox "Targeted: " & Me.Properties.Column(2)
     Me.txtTargeted = Me.Properties.Column(2)
End Sub

This will pop up a message box showing you if the event fires and the value.

What does it display?
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
 
Old January 29th, 2012, 10:31 AM
Registered User
 
Join Date: Jan 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sir I tried too all the code you've given to me but still not working.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate a text box from a combo box value dnf999 Access VBA 7 February 6th, 2012 02:24 PM
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
Combo box choice creating filtered combo box stevensj5 Access 11 September 13th, 2007 11:33 AM
Combo box and Text box Rudner Access VBA 4 November 16th, 2004 02:57 PM
Combo Box and Text Box Rudner Beginning VB 6 1 November 8th, 2004 04:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.