Results 1 to 4 of 4
  1. #1
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91

    Syntax error in SQL query for report

    Hi all,



    I'm displaying the DnerRegID from the PaymentsReceived table on this report. What I would like to do is to get the Doner firstname and last name from the donations table based on the DonerRegID. I keep getting a syntax error. Here is the code I have written. Any ideas.

    Select [Donations]![DonerLastName],[Donations]![DonerFirstName] WHERE [PaymentsReceived]![DonerRegID] = [DonerRegID]

    Kind Regards
    Karl

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I am not sure how you are displaying the result. Since I am guessing how I will suggest a solution. As for the code you are showing here. The WHERE statement seems to switch domains from the table named "Donations" to the table your report is using for a recordset.

    so
    WHERE [PaymentsReceived]![DonerRegID] = [DonerRegID]
    would probably work better as
    WHERE [Donations]![DonerRegID] = [DonerRegID]
    and you still probably need to define the report's current record association to [DonerRegID] after the equal sign.

    I don't know if the following code will slow down your DB too much but here is an option. This is assuming you have an unbound text box named "Me.txtAnswer" in the Header or Footer for your DonerRegID text box.

    Place the following VBA in the footer or header's format section for your report. Depending on where txtAnswer resides.

    Dim strFullName As String
    strFullName = DLookup("DonerLastName", "Donations", "[DonerRegID] =" & Me.DonerRegID)
    strFullName = strFullName & ", " 'Place a comma and a space after the Last Name
    strFullName = strFullName & DLookup("DonerFirstName", "Donations", "[DonerRegID] =" & Me.DonerRegID)
    Me.txtAnswer = strFullName



    .

  3. #3
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91
    Thanks for your help. Going to try that out now (all methods you suggested) ans see how I get on. Thanks again.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    There are other ways to go about it. Considering where you may be now, the above options are worth consideration.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  2. Syntax Error For Main Form Subform Report
    By burrina in forum Reports
    Replies: 1
    Last Post: 12-27-2012, 03:03 AM
  3. Replies: 4
    Last Post: 07-25-2012, 04:01 AM
  4. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  5. syntax error in query
    By zoe.ohara in forum Queries
    Replies: 6
    Last Post: 04-23-2011, 04:58 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums