Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Network    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
RunTime Error 3075
Warren Lovegrove 
     
4 years ago
I'm getting this error when transferring data to table, appears to relate to fields "Body" and "Cover".
States a "Syntax error (missing operator) in the query expression.
Would appreciate any direction you're able to provide, thanks.

Dim Body As String, Description As String, Cover As String, S As String, C As Currency
Dim db As Database
Dim rs As Recordset

    Set db = CurrentDb
    Set rs = db.OpenRecordset("Select * from TenantQ where TenantID=" & TenantCombo)

'Create Deed Document    
'Input into Body
    Description = DLookup("Subject", "DocumentTemplateT", "DocumentTemplateID=" & 6)
    Body = DLookup("Body", "DocumentTemplateT", "DocumentTemplateID=" & 6)
        
    ' Body Code Subtitutions
    If InStr(Body, "{TodayDate}") Then
        S = Date
        Body = Replace(Body, "{TodayDate}", S)
    End If
    If InStr(Body, "{TenantName}") Then
        S = DLookup("TenantName", "TenantQ", "TenantID=" & TenantCombo)
        Body = Replace(Body, "{TenantName}", UCase(S))
    End If
    If InStr(Body, "{CompanyNo}") Then
        S = DLookup("CompanyNo", "TenantT", "TenantID=" & TenantCombo)
        Body = Replace(Body, "{CompanyNo}", S)
    End If
    If InStr(Body, "{Guarantor}") Then
        S = DLookup("Guarantor", "TenantQ", "TenantID=" & TenantCombo)
        Body = Replace(Body, "{Guarantor}", UCase(S))
    End If
    If InStr(Body, "{CPIReviewDate}") Then
        S = DLookup("Anniversary", "TenantQ", "TenantID=" & TenantCombo)
        Body = Replace(Body, "{CPIReviewDate}", S)
    End If
    If InStr(Body, "{LegalDescription}") Then
        S = DLookup("LegalDescription", "TenantQ", "TenantID=" & TenantCombo)
        Body = Replace(Body, "{LegalDescription}", S)
    End If
    If InStr(Body, "{FullAddress}") Then
        S = DLookup("FullAddress", "TenantQ", "TenantID=" & TenantCombo)
        Body = Replace(Body, "{FullAddress}", S)
    End If
    If InStr(Body, "{FigPriorPrevious}") Then
        S = DLookup("FigPriorPrevious", "CPIReviewT", "TenantID=" & TenantCombo)
        Body = Replace(Body, "{FigPriorPrevious}", S)
    End If
    If InStr(Body, "{DatePriorCurrentPrevious}") Then
        S = DLookup("FigPriorCurrent", "CPIReviewT", "TenantID=" & TenantCombo)
        Body = Replace(Body, "{FigPriorCurrent}", S)
    End If
     If InStr(Body, "{FigPriorCurrent}") Then
        S = DLookup("FigPriorPrevious", "CPIReviewT", "TenantID=" & TenantCombo)
        Body = Replace(Body, "{FigPriorPrevious}", S)
    End If
    If InStr(Body, "{DatePriorCurrent}") Then
        S = DLookup("FigPriorCurrent", "CPIReviewT", "TenantID=" & TenantCombo)
        Body = Replace(Body, "{FigPriorCurrent}", S)
    End If
    If InStr(Body, "{CPIRateApplicable}") Then
        S = DLookup("CPIRateApplicable", "CPIReviewT", "TenantID=" & TenantCombo)
        Body = Replace(Body, "{CPIRateApplicable}", S)
    End If
    If InStr(Body, "{ProposedRentExclGST}") Then
        C = Nz(DLookup("ProposedRentExclGST", "CPIReviewT", "TenantID=" & TenantCombo), 0)
        S = Format(C, "Currency")
        Body = Replace(Body, "{ProposedRentExclGST}", S)
        End If
    If InStr(Body, "{NewMonthlyRent}") Then
        C = Nz(DLookup("NewMonthlyRent", "CPIReviewT", "TenantID=" & TenantCombo), 0)
        S = Format(C, "Currency")
        Body = Replace(Body, "{NewMonthlyRent}", S)
    End If
    If InStr(Body, "{ETotalOPEX}") Then
        C = Nz(DLookup("ETotalOPEX", "CPIReviewT", "TenantID=" & TenantCombo), 0)
        S = Format(C, "Currency")
        Body = Replace(Body, "{ETotalOPEX}", S)
        End If
    If InStr(Body, "{ETotalMonthlyOPEX}") Then
        C = Nz(DLookup("ETotalMonthlyOPEX", "CPIReviewT", "TenantID=" & TenantCombo), 0)
        S = Format(C, "Currency")
        Body = Replace(Body, "{ETotalMonthlyOPEX}", S)
    End If
    
    Me.Refresh
    
    'Input Cover Page
    Cover = DLookup("Body", "DocumentTemplateT", "DocumentTemplateID=" & 4)
    ' Cover Page Code Subtitutions
    If InStr(Cover, "{TenantName}") Then
        S = DLookup("TenantName", "TenantQ", "TenantID=" & TenantCombo)
        Cover = Replace(Cover, "{TenantName}", UCase(S))
    End If
    If InStr(Cover, "{Guarantor}") Then
        S = DLookup("Guarantor", "TenantQ", "TenantID=" & TenantCombo)
        Cover = Replace(Cover, "{Guarantor}", UCase(S))
    End If
    If InStr(Cover, "{Subject}") Then
        S = DLookup("Subject", "DocumentTemplateT", "DocumentTemplateID=" & 6)
        Cover = Replace(Cover, "{Subject}", UCase(S))
    End If
    
    Me.Refresh
    
    If MsgBox("Do you wish to transfer Document data to relevant Table?" & vbNewLine & vbNewLine & "i.e. DocumentT", vbYesNoCancel, "Transfer Data") = vbYes Then
    CurrentDb.Execute "INSERT INTO DocumentT (TenantID, DocumentDate, Description, Notes, Cover)" & "VALUES(" & rs!TenantID & ", #" & Date & "#, '" & Description & "', '" & Body & "', '" & Cover & "')"
    MsgBox "Transfer Completed", vbOKOnly, "Data Transfer"
    Else
    End If
Adam Schwanz  @Reply  
           
4 years ago
If you push debug what line does it go to? There's probably a missing parenthesis or something but that's too much for me to want to scrape through right now.
Adam Schwanz  @Reply  
           
4 years ago
Also why use a recordset at all for this? The only time you call for it is once at the end rs!TenantID. You could just do TenantCombo
Alex Hedley  @Reply  
           
4 years ago
Always make the SQL string a variable,
Then you can MsgBox, Debug.Print etc before you run execute
Helps with debugging
Kevin Yip  @Reply  
     
4 years ago
Most likely the value of Body contains single quotes.  In string concatenation, you need to replace all single quotes in string values with "double single quotes."  Sometimes you need to use double double quotes as well.  E.g.

CurrentDb.Execute "INSERT INTO DocumentT (TenantID, DocumentDate, Description, Notes, Cover)" & "VALUES(" & rs!TenantID & ", #" & Date & "#, '" & Description & "', '" & Replace(Body, "'","''") & "', '" & Cover & "')"

One way to avoid this kind of headache is, instead of using an SQL statement, use the Recordset object to insert the record.  You don't need to double up the quotes, and you don't need "#" for dates, because everything is passed to the recordset as it is:

    Dim r As Recordset
    Set r = CurrentDb.OpenRecordset("DocumentT")
    r.AddNew
    r!TenantID = TenantID
    r!DocumentDate = Date
    r!Description = Description
    r!Notes = Body
    r!Cover = Cover
    r.Update  

Another way to avoid this is, instead of using standard single (or double) quotes in your data, using the special quotes in the picture below.

Kevin Yip  @Reply  
     
4 years ago

Warren Lovegrove OP  @Reply  
     
4 years ago
Thanks so much for your help.
Kevin, you were spot with the replacing of all single quotes.

Thanks
Warren

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Network.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/30/2026 5:20:16 PM. PLT: 0s