DLookup Help?

gmatriix

Registered User.
Local time
Today, 09:08
Joined
Mar 19, 2007
Messages
365
Hello All,

What I am trying to do is when I choose a value in a drop down this will populate the the next field called "cutoff" based off of the drop down.

Is there a easy way to do this in VBA? I tried this but it is not working

Code:
Private Sub Cutoff_AfterUpdate()

Dim varX As Variant

varX = DLookup("[Cutoff]", "qMachGroup", _
    "[Machine Size]= " & Forms!Product!Combo76)

End Sub


Any Ideas?
 
Thanks,

I tried this below and I get runtime 2471.....sorry I'm still learning.....

Code:
Private Sub Cutoff_Click()
Dim varX As Variant


varX = DLookup("Cutoff", "qMachGroup", "[Machine Size] = '" & Me.Combo76 & "'")

Me.Cutoff = varX
End Sub

The reason I need code is because I need for the user to overwrite the value in the cutoff field...

Ideas?
 
DLOOKUPS are expensive. They iterate every record of a continuous form on the Load event. You may want to adjust the recordsource of the Autopopulating field to be "SELECT whatyouwant FROM yourtable WHERE whatyouwant = " & Forms!Product!Combo76.
 
Not having them memorized, what is error 2471? Is the size field numeric or text? Is the other link not applicable?
 
Thanks michaeljryan78

That make sense however, I need the user to be able to overwrite the field. The drop down will just reset it to default.

So they can use the drop down...but if they wanted to change the amount they can...

Thats why Im trying to do it in code....trying anyway

any suggestions?
 
Yes, read my link all the way to the bottom.
 
Pbaldy,

I changed it to this
Code:
Private Sub Cutoff_Click()
Dim varX As Variant


varX = DLookup("[Cutoff]", "[qMachGroup]", "[MachineSize] = '" & Me.Combo76 & "'")

Me.Cutoff = varX
End Sub

No error now...but still nothing...what event should I have this on?

Whenever I change what is in the drop down...it should populate the field "Cutoff"

Ideas?
 
You want the after update event.
 
Ok,

I put it on the afterupdate event on the cutoff field and I'm am still getting nothing....

Is there something wrong with my code?
 
Have you tried the more efficient:

Me.Cutoff = Me.Combo76.Column(2)

Replacing 2 with the appropriate column? By the way, you're using the events of the Cutoff field; it needs to be the combo's after update event.
 
pbaldy,

I tried Me.Cutoff = Me.Combo76.Column(2) and I did not get anything....

not sure what is wrong...I tried

Code:
Private Sub Combo76_AfterUpdate()
Dim varX As Variant

varX = DLookup("[CutoffWidth]", "[qMachGroup]", "[MachineSize] = '" & Me.Combo76 & "'")
Me.Cutoff = varX
End Sub

On the combo box and it populating 0 in the Cutoff field....
 
Did you adjust the number to match the column (remembering that the property is zero based)? Can you post the db here?
 
Here is just an example of what I have,

The db I have is too big

Thanks
 

Attachments

It would be this since you only have 2 fields:

Me.Cutoff = Me.Combo0.Column(1)

But that errors because it's trying to put a text value like "1 in and below" into a numeric field. Perhaps another field needs to be added?
 
Well what I want to return is the CutoffWidth which is numbers like 0.145....this number should populate in the cutoff field..
 
Add that to the row source, change the column count and widths properties and change the 1 to a 2 in my code.
 
Im sorry,

I will not be about to overwrite the Cutoff field if I put it in the row source....that why I was trying to create a vb code for it.

I don't mean to be pain with this....
 
The ROW source, not the CONTROL source. The query that provides the dropdown options.
 
Can I send that testdb12 back with your changes...so I can make sure I have it right?
 

Users who are viewing this thread

Back
Top Bottom