What's strStart = [tblWarehouse.PostCodeChar] = " & Left([Postcode],2) & "
supposed to be?
If I'm understanding correctly, it should be simply:
strStart = Left([PostCode], 2)
However, let's step back a moment.
You're looking up Warehouse in tblWarehouse and storing it in tblContacts.
Why? Isn't PostalCode in both tables (either entirely, or in part)? You have
sufficient information to join the two tables together in a query, rather
than storing the Warehouse information redundantly.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Postcode is in tblContacts. I have another table so that it can lookup
the
value supposed to be in the Postcode field of tblContacts. That table is
tblWarehouse.
But....I'm running into guessing now, this is what I have...
Private Sub Warehouse_AfterUpdate()
strWarehouse = Me.Warehouse
strStart = [tblWarehouse.PostCodeChar] = " & Left([Postcode],2) & "
CurrentDb.Execute "UPDATE [tblContacts] " & SET [Warehouse] = '" &
strWarehouse & "'" & " WHERE Postcode LIKE '" & strStart & "*'",
dbFailOnError
End Sub
I know it's wrong, but this one is more difficult than I thought.
:
Is Postcode in tblContacts?
If so, then try something like:
CurrentDb.Execute "UPDATE [tblContacts] " & _
SET [Warehouse] = '" & strWarehouse & "'" & _
" WHERE Postcode LIKE '" & strStart & "*'", dbFailOnError
(where strStart contains the first 2 characters of the Postcode).
If Postcode isn't in tblContacts, how do you know which rows need to be
updated?
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Ok, so i have to put
(in English) Warehouse Value is Kendal WHERE postcode starts with LA,
Warehouse Value is Rushden WHERE postcode starts with NE, Warehouse
Value
is
Bristol where postcode starts with BR, etc, etc.....except theres over
100
postcode values!!! That's why I created the table so the unbound value
on
the
form could look up the value in the Warehouse table. I have seen
somewhere
(on a wizard I think) an option to store a certain value in a certain
field,
that's exactly what i need.
:
Your UPDATE statement is incorrect then: because there's no WHERE
clause,
it's going to update every row.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
No I want each row to have either "Kendal", "Rushden" or "Bristol"
as
it's
value depending on postcode.
:
So you want every single row in tblContacts to have the same
value
for
Warehouse, and that's not happening?
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
I have a DLookup in the form field which looks up a table with
the
first
two
characters of the post code matched with one of three
warehouses,
which
works
perfectly. After the field looks up the value and is updated,
I
need
that
returned value to store in another table. So the correct
value is
in
strWarehouse as far as I can tell.
The code you gave me is doing the same thing, no error, but
not
updating
the
table either.
Thanks.
:
Do you know that the correct value is in strWarehouse?
Try using the Execute method of the database: that'll let
you
trap
for
errors:
CurrentDb.Execute "UPDATE [tblContacts] SET [Warehouse] = '"
&
strWarehouse
& "'", dbFailOnError
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
message
I have searched this newsgroup for the best solution but
nothing
seems
to
work. I have coded the following to the AfterUpdate event
of
the
Warehouse
field on my form...
strWarehouse = Me.Warehouse
DoCmd.RunSQL "UPDATE [tblContacts] SET [Warehouse] = '" &
strWarehouse
&
"'"
However, it's not working, not returning anything, but no
error?
What's
wrong?
Thanks