Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Seminars   Templates   TechHelp   Fast Tips   Forums   Help   Contact   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > Track Changes < Form Backgrounds | Command Line >
 
Track Changes
By Richard Rost   Richard Rost on Twitter Richard Rost on LinkedIn Email Richard Rost   2 years ago


Back to Track Changes
 

Issue with VBA Upload Images   Link  
Glenn Kraniske 
4 months ago
Hello All,
I watched a video that Rick posted about logging database changes to another table.  See below;

https://www.youtube.com/watch?v=3sIHMGxugL0&t=313s

It works great right up until I try to add a new record.  I get a message that says:

Rintime Error '3075'
Syntax error (missing operator) in query expression 'FishingPoleID='

Here's the VBA code I used:

Private Sub Form_BeforeUpdate(Cancel As Integer)

    DoCmd.SetWarnings False
    DoCmd.RunSQL "INSERT INTO dbo_FishingPoleChangeLog SELECT * FROM dbo_FishingPoles " & _
    "WHERE FiishingPoleID=" & FishingPoleID
    DoCmd.SetWarnings True
    
End Sub


Any help would be appreciated.  Oh and by the way, I'm using a SQL Server backend.  Thanks in advance.

Glenn
Alex Hedley
4 months ago
MsgBox FishingPoleID
What do you get?
Kevin Robertson
4 months ago
You have a mis-spelling in this line

"WHERE FiishingPoleID=" & FishingPoleID
Glenn Kraniske
4 months ago
Forgive me but I'm new at this.  I saw this mis-spelling just now but rest assured, there isn't one in the database.  I'm just using fishing poles so I don't have to divulge the actual db name.  Not sure what to do with the MsgBox thing.
Adam Schwanz
4 months ago
Is FishingPoleID a short text field by chance? You may need Double Double Quotes
Glenn Kraniske
4 months ago
It's an autonumber in Access, an INT in sql server
Glenn Kraniske
4 months ago
Still tearing my hair out.  I had to put a TIMESTAMP column in the table just so I could add and change records.  I was getting a write conflict error which is why I had to add the TIMESTAMP column.  I've searched all over the internet for VBA code to add to my database to get it to add the changed data to the appropriate table but all I'm getting is errors.  Here's the code if anyone could possible tweak it for me.  Thanks again.

Private Sub Form_Dirty(Cancel As Integer)
    DoCmd.SetWarnings False
    DoCmd.RunSQL "SELECT * INTO FiishingTemp FROM dbo_FishingPoles"
    DoCmd.RunSQL "ALTER TABLE FishingTemp DROP COLUMN TMP"
    DoCmd.RunSQL "SELECT * FROM FishingTemp"
    DoCmd.RunSQL "DROP TABLE FishingTemp"
    DoCmd.RunSQL "INSERT INTO dbo_FishingPoleChangeLog SELECT * FROM FishingTemp " & _
    "WHERE FishingPoleID=" & FishingPoleID
    DoCmd.SetWarnings True
End Sub
Alex Hedley
4 months ago
If you hardcore the ID and run the SQL manually in a Query window does it work?
Glenn Kraniske
4 months ago
Yes - I only tried this portion of it but it worked.

DoCmd.RunSQL "SELECT * INTO FiishingTemp FROM dbo_FishingPoles"
DoCmd.RunSQL "ALTER TABLE FishingTemp DROP COLUMN TMP"
DoCmd.RunSQL "SELECT * FROM FishingTemp"
DoCmd.RunSQL "DROP TABLE FishingTemp"
Kevin Robertson
4 months ago
It looks like you are referring to a table (FishingTemp) in your INSERT Into statement that has already been deleted.
Glenn Kraniske
4 months ago
Yeah when I ran it in the SQL Management Studio it errored out so I moved the DROP TABLE statement to the end.  It works if I run it in SQL Management Studio but I'm not sure what the syntax is in VBA.
Glenn Kraniske
4 months ago
I only want the changed records to get copied to the ChangeLog table
Alex Hedley
4 months ago
I think you're trying too much at once
Break it down into single steps.

Step 1
Can you insert a single record into a table

INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

Try this in the Query window of Access manually.
Glenn Kraniske
4 months ago
Alex,
Thanks for your help, I truly appreciate it.  Yes, that worked just fine.
Alex Hedley
4 months ago
Great, next step is

INSERT INTO dbo_FishingPoleChangeLog SELECT * FROM dbo_FishingPoles WHERE FishingPoleID=1

Swap 1 for a valid id.
Glenn Kraniske
4 months ago
Alex,
No that doesn't work.  The TMP field is a TIMESTAMP type field in the SQL database.  I had to add it so I could insert more records.  When I started messing around with the code I got a write conflict error.  I'll upload a screen shot.
Glenn Kraniske
4 months ago

Alex Hedley
4 months ago
Is TMP a datetime field?
Update the below with a new Date() or Now() etc

INSERT INTO dbo_FishingPoleChangeLog SELECT *, 'TIMESTAMP' AS TMP FROM dbo_FishingPoles WHERE FishingPoleID=1
Kevin Robertson
4 months ago
Could this be the reason for the unknown field error?
Kevin Robertson
4 months ago

Glenn Kraniske
4 months ago
I'm not sure.  Like I said I had to add that column in the SQL table just so I could enter and modify records.  Without it I get a write conflict.  In the SQL table it's a TIMESTAMP data type, however, in Access it shows up as BINARY and I don't think Access knows how to deal with it which is why I dropped the column in the VBA code.  I'm definitely open to recommendations.
Alex Hedley
4 months ago
Did the next step work?
Glenn Kraniske
4 months ago
Everything worked as long as I didn't include the BINARY column in the SQL query.  In VBA I'm not sure where the breakdown occurred.
Alex Hedley
4 months ago
Not following,
The second piece of SQL I asked you to try (INSERT INTO) did that work?
Glenn Kraniske
4 months ago
No, it errored out on the TMP column
Alex Hedley
4 months ago
What SQL did you try and what was the error?

(Also is it worth creating the table in Access and transferring it to MS SQL instead of creating it directly in MS SQL, although when you pull it down to Access it should understand it, does it show the datetime correctly in a Table view or Form?)
Glenn Kraniske
4 months ago
Hello again everybody,

Thank you all for your help, I just wanted to give you all an update.  I was able to accomplish this task using a SQL Server "Trigger."  It's a work in progress but it's coming along.  If you want to see the code let me know and give me a way to contact you so I don't have to publicly post it.  Have a great day!!

This thread is now closed. If you wish to comment, start a NEW discussion, below.
 


Back to Track Changes Comments
 

Start a NEW Conversation
 
Only students may post right now. Click here for more information on how you can set up an account. If you are a student, please LOG ON first.
 
Subscribe
 

You may want to read these articles from the 599CD News:

5/31/2022List Items Set Value
5/28/2022Access Bug Alert #Deleted
5/27/2022Add Anything
5/26/2022List Items Edit Form
5/25/2022Column Colors
5/24/2022Multi-Table Forms
5/23/2022Variables
5/21/2022Access Developer 39
5/21/2022Access Developer 39 Lessons
5/21/2022Access Developer 39
 

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
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
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn