Problem running SQL from a form

Al Kramer

Member
Local time
Today, 03:31
Joined
Jan 7, 2025
Messages
54
Hello All
I have a query that runs perfectly. When I copy the SQL code from it into the click event of a button I get a compile error. The SQL is a bit complex but as i said it runs fine in the query.
1739825520458.png


SQL...
SELECT Demo.PREFIX, Demo.FNAME, Demo.LNAME, Demo.PREFIX2, Demo.FNAME2, Demo.LNAME2, Switch(IsNull([Fname2]),[demo.Prefix] & " " & [Fname] & " " & [Lname],(IsNull([Lname2]) And Not IsNull([Fname2])) Or ([Lname]=[Lname2]),[demo.Prefix] & " & " & [demo.Prefix2] & " " & [Fname] & " " & [Lname],Not IsNull([Lname2]) And [lname]<>[Lname2],[demo.Prefix] & " " & [Fname] & " " & [Lname] & " and " & [demo.Prefix2] & " " & [Fname2] & " " & [Lname2]) AS Greet, Payment.GIFT_TYPE, Demo.STREET1, Demo.STREET2, Demo.CITY, Demo.STATE, Demo.ZIP, Payment.GIFTDATE, [demo.city]+" " & [demo.state]+" " & [demo.zip] AS cityline, Payment.AMOUNT INTO TblAckLetter
FROM Demo INNER JOIN Payment ON Demo.Id = Payment.fkDemoId
WHERE (((Payment.GIFTDATE) Between [StartDate] And [EndDate]));


Any thoughts appreciated.
 
What error were you getting? I think the RunSQL method only applies to action queries (Append, Delete, etc.) It looks like you're trying to run a Select query though.
 
Yes I was, I'm such a beginner I didn't realize all I had to do was create a macro to call the query. Problem solved
Thanx
 
Yes I was, I'm such a beginner I didn't realize all I had to do was create a macro to call the query. Problem solved
Thanx
Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom