Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Accessing Value for Query (Access 2000)

    I'm using the following code to step through a table and use the DivisionName value to create another table. I'm then planning to send the table in Excel format to the user. When I run the code it shows a messagebox with the value in. Where am I going wrong with the syntax.

    Set DB = CurrentDb
    Set RS = DB.OpenRecordset("tblMFDCostOverR50DivEmail", dbOpenDynaset)
    Set DivisionName = RS![DivName]

    Do While RS.EOF = False

    DoCmd.RunSQL "SELECT tblMFDCostOverR50.DivName, tblMFDCostOverR50.AccountNo
    INTO tblMFDCostOverR50DivisionsEmail FROM tblMFDCostOverR50
    WHERE (((tblMFDCostOverR50.DivName)=" & DivisionName & "));"
    RS.MoveNext

    Loop

    TIA

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Accessing Value for Query (Access 2000)

    I assume that DivisionName is a text field. If that is correct, you must enclose the value in quotes. To use quotes in a string in code, you can use Chr(34):

    DoCmd.RunSQL "SELECT DivName, AccountNo " & _
    "INTO tblMFDCostOverR50DivisionsEmail FROM tblMFDCostOverR50 " & _
    "WHERE DivName=" & Chr(34) & DivisionName & Chr(34)

  3. #3
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Accessing Value for Query (Access 2000)

    Thanks Hans

Posting Permissions

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