Weird DLookUp Problem (1 Viewer)

Fazered

Registered User.
Local time
Today, 08:06
Joined
Mar 25, 2008
Messages
29
Right, so i have a table which hase pricing information, and i am trying to do a DLookUp in it to find the Unique ID (MixID) for a given Mix (Mixes).

So, i wrote a subroutine to do this and set values for me, but despite the huge number of DLookup's already in the whole project (well over 30-40) and they all work like charm.
This being the case i have check, and double checked the DLookUp to see if i can find any mistakes, but i can't seem to find any.

Here is the Code:

Code:
Public Sub SelectMix()

Dim MixIDVar As Integer

On Error Resume Next
    If Not Mixes.Value = "" Then
   
        'Pass the selected value to the quote mix
        Form_PriceList.txtQuoteMix.Value = Me.Mixes.Value

        'Get the numerical ID for the mix
        MixIDVar = DLookup("MixID", "MixesPricing", "Mixes=" & Mixes.Value)
        Form_PriceList.txtQuoteMixID.Value = MixIDVar
        
    End If
On Error GoTo 0

End Sub

And here is the table which it should be looking through:


The majority of the textboxes which are referenced in this subroutine are part of a form which displays the table above. This form is then included in another form as a subform. The subroutine above is ran when a user double clicks on a field in the subform and passes one or two values back to the main form.


Can anyone see anything that i am missing?
 

CyberLynx

Stuck On My Opinions
Local time
Today, 00:06
Joined
Jan 31, 2008
Messages
585
Off the hop, a couple things:

The Table Field MixID will be of a Long Integer Data Type since it appears to be a AutoNumber Field. With that in mind:

Dim MixIDVar As Long

is required rather than:

Dim MixIDVar As Integer

Looking at the Posted Image, The Mixes Table Field appears to be of a Text Data Type and therefore when referencing Data to and from that Field, apostrophes need to be used. For example:

MixIDVar = DLookup("MixID", "MixesPricing", "Mixes='" & Mixes.Value & "'")

If you comment out the: On Error Resume Next then chances are an error will be raised and tell you the problem.

.
 

Fazered

Registered User.
Local time
Today, 08:06
Joined
Mar 25, 2008
Messages
29
Thanks for your reply, thankfully i managed to find a site where someone had exactly the same problem and so i have managed to get it fixed. What you suggested was exactly what i needed to do.
Thanks anyway.
 

Users who are viewing this thread

Top Bottom