Display selection from combobox in a text box

G

Guest

I have a subform whcih allows me to select a number of services for each
order I receive (drilling, excavation, survey, screening etc..). Each option
listed in the combo box display the service, estimated time, and estimated
cost. Once a service is selected only the service type is displayed (such as
excavation) and I would like to have the other information (estimated time
and cost) displayed in an additional text box. I have been trying to do this
with VBA however I keep getting an error.

Below is the code which I am using, could someone please help me identify my
error?

Private Sub ServiceID_AfterUpdate()
Dim strfilter As String

On Error GoTo errorhandler

strfilter = "ServiceID=" & Me!ServiceID

Me.Description = DLookup("Descritpion", "tblService", strfilter)

Exit Sub

errorhandler:
MsgBox "Error#" & Err.Number & vbCrLf & Err.Description
 
J

jahoobob via AccessMonster.com

Put this in the AfterUpdate fo ServiceID
me.[ET] = me.[ServiceID].column(1)
assuming that estimated time is in the second column of the combo box and
that the text box in which you want to display it is named ET.
Note: VBA starts numbering columns of a combo at 0, thus the 1 for the second
column.
 
G

Guest

It looks like it will work however each time I try it I get an error message
telling me that the field is to small to accept the amount of data I am
attemptiing to add. Is there a way to correct this?

jahoobob via AccessMonster.com said:
Put this in the AfterUpdate fo ServiceID
me.[ET] = me.[ServiceID].column(1)
assuming that estimated time is in the second column of the combo box and
that the text box in which you want to display it is named ET.
Note: VBA starts numbering columns of a combo at 0, thus the 1 for the second
column.
I have a subform whcih allows me to select a number of services for each
order I receive (drilling, excavation, survey, screening etc..). Each option
listed in the combo box display the service, estimated time, and estimated
cost. Once a service is selected only the service type is displayed (such as
excavation) and I would like to have the other information (estimated time
and cost) displayed in an additional text box. I have been trying to do this
with VBA however I keep getting an error.

Below is the code which I am using, could someone please help me identify my
error?

Private Sub ServiceID_AfterUpdate()
Dim strfilter As String

On Error GoTo errorhandler

strfilter = "ServiceID=" & Me!ServiceID

Me.Description = DLookup("Descritpion", "tblService", strfilter)

Exit Sub

errorhandler:
MsgBox "Error#" & Err.Number & vbCrLf & Err.Description
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top