Dlookup

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I did the following in the code for a form and I am getting nothing as a
result:

Private Sub VIN_BeforeUpdate(Cancel As Integer)
Dim varX As Variant
varX = DLookup("[VIN]", "contract", "[Contract number] = SPB750690")
End Sub

Any suggestions?
 
Since Control Number is a text field, you need quotes around the value
you're checking for:

varX = DLookup("[VIN]", "contract", "[Contract number] = 'SPB750690'")

However, what do you expect that to do? All you're doing is assigning it to
a local variable varX. Once Sub VIN_BeforeUpdate completes execution, that
value will be lost.
 
I want the VIN # to display in the field.

Douglas J Steele said:
Since Control Number is a text field, you need quotes around the value
you're checking for:

varX = DLookup("[VIN]", "contract", "[Contract number] = 'SPB750690'")

However, what do you expect that to do? All you're doing is assigning it to
a local variable varX. Once Sub VIN_BeforeUpdate completes execution, that
value will be lost.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


dalaw said:
I did the following in the code for a form and I am getting nothing as a
result:

Private Sub VIN_BeforeUpdate(Cancel As Integer)
Dim varX As Variant
varX = DLookup("[VIN]", "contract", "[Contract number] = SPB750690")
End Sub

Any suggestions?
 
I believe you should enclose contract number field in ' '. The only time you leave the ' off is when the field is numeric. Hope this works. I hav eassumed that contract number is a TEXT field.

varX = DLookup("[VIN]", "contract", "[Contract number] = 'SPB750690' ")
 
Assuming you want VIN # to appear in the textbox named VIN, putting that
code in the BeforeUpdate event probably isn't the most appropriately event.

You'd want

Me.VIN = DLookup("[VIN]", "contract", "[Contract number] = 'SPB750690'")

but where you want it depends on how you're getting the Contract number.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


dalaw said:
I want the VIN # to display in the field.

Douglas J Steele said:
Since Control Number is a text field, you need quotes around the value
you're checking for:

varX = DLookup("[VIN]", "contract", "[Contract number] = 'SPB750690'")

However, what do you expect that to do? All you're doing is assigning it to
a local variable varX. Once Sub VIN_BeforeUpdate completes execution, that
value will be lost.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


dalaw said:
I did the following in the code for a form and I am getting nothing as a
result:

Private Sub VIN_BeforeUpdate(Cancel As Integer)
Dim varX As Variant
varX = DLookup("[VIN]", "contract", "[Contract number] = SPB750690")
End Sub

Any suggestions?
 
Where do I put the code below in the form properties? I want it to display
Assuming you want VIN # to appear in the textbox named VIN, putting that
code in the BeforeUpdate event probably isn't the most appropriately event.

You'd want

Me.VIN = DLookup("[VIN]", "contract", "[Contract number] = 'SPB750690'")

but where you want it depends on how you're getting the Contract number.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


dalaw said:
I want the VIN # to display in the field.

Douglas J Steele said:
Since Control Number is a text field, you need quotes around the value
you're checking for:

varX = DLookup("[VIN]", "contract", "[Contract number] = 'SPB750690'")

However, what do you expect that to do? All you're doing is assigning it to
a local variable varX. Once Sub VIN_BeforeUpdate completes execution, that
value will be lost.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I did the following in the code for a form and I am getting nothing as a
result:

Private Sub VIN_BeforeUpdate(Cancel As Integer)
Dim varX As Variant
varX = DLookup("[VIN]", "contract", "[Contract number] = SPB750690")
End Sub

Any suggestions?
 
Put the code in the AfterUpdate event of the Contract Number text box then.

Private Sub Contract_AfterUpdate()

Me.VIN = DLookup("[VIN]", "contract", "[Contract number] = '" &
Me.Contract & "'")

End Sub


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


dalaw said:
Where do I put the code below in the form properties? I want it to
display
on the form when I put the contract number on the form. I actually want
the
"spb750690" to be a variable that I put in another text box.

Douglas J Steele said:
Assuming you want VIN # to appear in the textbox named VIN, putting that
code in the BeforeUpdate event probably isn't the most appropriately
event.

You'd want

Me.VIN = DLookup("[VIN]", "contract", "[Contract number] =
'SPB750690'")

but where you want it depends on how you're getting the Contract number.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


dalaw said:
I want the VIN # to display in the field.

:

Since Control Number is a text field, you need quotes around the
value
you're checking for:

varX = DLookup("[VIN]", "contract", "[Contract number] =
'SPB750690'")

However, what do you expect that to do? All you're doing is assigning
it to
a local variable varX. Once Sub VIN_BeforeUpdate completes execution, that
value will be lost.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I did the following in the code for a form and I am getting nothing
as a
result:

Private Sub VIN_BeforeUpdate(Cancel As Integer)
Dim varX As Variant
varX = DLookup("[VIN]", "contract", "[Contract number] =
SPB750690")
End Sub

Any suggestions?
 
Back
Top