Results 1 to 2 of 2
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Thanked 0 Times in 0 Posts

    where statement (Access 2000)

    I have a recurring where statement and in order to make short the code i would like
    to make a special string called strWhere. For example i want toi remake the following code:
    strSQL = "UPDATE Products SET branch1 = branch1 - " & Me.cartons & " WHERE ProductID=" & Me.ProductID

    This code works fine. But i want to be read like that:

    dim StrWhere = &" WHERE ProductID= " & Me.ProductID"
    StrSql = = "UPDATE Products SET branch1 = branch1 - " & Me.cartons & strWhere

    However the code does not function and i suspect my StrWhere is wrong, since otherwise, with the original code
    it works.
    I will be grateful for any help

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Sacramento, California, USA
    Thanked 1 Time in 1 Post

    Re: where statement (Access 2000)

    If you only want the Where condition in your strWhere, and you want to be able to easily debug the SQL strings as you move through records, do this:

    Dim strWhere as String
    Dim strSQL As String

    strSQL = "UPDATE Products SET branch1 = branch1 - " & Me.cartons

    strWhere = " WHERE ProductID=" & Me.ProductID

    Then concatenate strSQL and strWhere to get your final SQL statement. Make sure you watch out for the space between the end of strSQL and the "Where" in strWhere. If you leave out the space, you'll get a syntax error in your SQL.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts