Psycholicon
Registered User.
- Local time
- Today, 05:04
- Joined
- Aug 14, 2007
- Messages
- 33
Hi, I'm learning SQL (and Access for that matter) as I go, so I apologize for having terrible syntax, but if you could help me anyway, it'd be a lifesaver.
In my DB there are notices that are issued that make revisions, additions, or deletions to drawings. However, some of these notices do not get finalized, and so everything has to be tentative right up until the end, when it is released. My way of dealing with this is to duplicate the master Drawing Log table and retitle it with the number of the notice (ex. 07-23 Log). Then the edits are done in this table and when the notice is released they are transferred to the master table and the duplicate is deleted. The tables are made fine and work, but when I try to use SQL statements to update and insert into the duplicate, the TableName string doesn't work for some reason. If I put in the actual name, it works, but in operation that has to be variable. I know it's something easy, but I can't figure it out, and I'm tearing my hair out!.
Sorry for the long explanation. Here's some of the sample code:
To add:
Number = Me.Parent.DCN_Number.Value
TableName = Number & " Log"
DoCmd.RunSQL "INSERT INTO " & TableName & " ([Drawing Number],[Description],[Last Date]) VALUES ('" & AddDrawingNumber & "','" & DrawingDescription & "',#" & Me.Parent.[DCN Date] & "#)"
To delete:
Number = Me.Parent.DCN_Number.Value
TableName = Number & " Link"
DoCmd.RunSQL "DELETE FROM " & TableName & " WHERE [Drawing Number] = '" & DeleteDrawingNumber & "'"
To revise (CurrentRevision comes from code that moves it one letter up)
Number = Parent.DCN_Number.Value
TableName = "" & Number & " Log"
DoCmd.RunSQL "UPDATE " & TableName & " SET [Current Revision] ='" & CurrentRevision & "' WHERE [Drawing Number] =" & "[Forms]![DCNs]![DCN Details Subform]![Drawing Number]"
DoCmd.RunSQL "UPDATE " & TableName & " SET [Last Date] ='" & Me.Parent.[DCN Date] & "' WHERE [Drawing Number] =" & "[Forms]![DCNs]![DCN Details Subform]![Drawing Number]"
Please don't be angry with how horrible it looks. Any pointers you could give on better efficiency would also be greatly appreciated, but I am really amateur when it comes to programming.
In my DB there are notices that are issued that make revisions, additions, or deletions to drawings. However, some of these notices do not get finalized, and so everything has to be tentative right up until the end, when it is released. My way of dealing with this is to duplicate the master Drawing Log table and retitle it with the number of the notice (ex. 07-23 Log). Then the edits are done in this table and when the notice is released they are transferred to the master table and the duplicate is deleted. The tables are made fine and work, but when I try to use SQL statements to update and insert into the duplicate, the TableName string doesn't work for some reason. If I put in the actual name, it works, but in operation that has to be variable. I know it's something easy, but I can't figure it out, and I'm tearing my hair out!.
Sorry for the long explanation. Here's some of the sample code:
To add:
Number = Me.Parent.DCN_Number.Value
TableName = Number & " Log"
DoCmd.RunSQL "INSERT INTO " & TableName & " ([Drawing Number],[Description],[Last Date]) VALUES ('" & AddDrawingNumber & "','" & DrawingDescription & "',#" & Me.Parent.[DCN Date] & "#)"
To delete:
Number = Me.Parent.DCN_Number.Value
TableName = Number & " Link"
DoCmd.RunSQL "DELETE FROM " & TableName & " WHERE [Drawing Number] = '" & DeleteDrawingNumber & "'"
To revise (CurrentRevision comes from code that moves it one letter up)
Number = Parent.DCN_Number.Value
TableName = "" & Number & " Log"
DoCmd.RunSQL "UPDATE " & TableName & " SET [Current Revision] ='" & CurrentRevision & "' WHERE [Drawing Number] =" & "[Forms]![DCNs]![DCN Details Subform]![Drawing Number]"
DoCmd.RunSQL "UPDATE " & TableName & " SET [Last Date] ='" & Me.Parent.[DCN Date] & "' WHERE [Drawing Number] =" & "[Forms]![DCNs]![DCN Details Subform]![Drawing Number]"
Please don't be angry with how horrible it looks. Any pointers you could give on better efficiency would also be greatly appreciated, but I am really amateur when it comes to programming.