I have a form linked to a table which is used to edit the table. There is a button to save the table, but I also want to add the function of creating a new entry for a backup table to preserve the old record (with a version number that changes to know which versions are which). I keep hitting error 3075 in my SQL (and other assorted bugs). Here's a shortened version of the VBA (there are about fifty fields, so I'll save you the trouble and give you a few)
Option Compare Database
Dim Rpt_Asset_IDV As Integer
Dim Report_NameV As String
Dim Report_DescriptionV As String
Dim Business_ValueV As String
Private Sub cmdSave_Click()
If MsgBox("Saving the changes will update the record. Are you sure you wish to save?", vbYesNo) = vbYes Then
Rpt_Asset_IDV = Me.Rpt_Asset_ID.Value
Report_NameV = Me.Report_Name.Value
Report_DescriptionV = Me.Report_Description.Value
If Not IsNull(Me.Business_use) Then BusinessValueV = Me.Business_use.Value
Call Master_Asset_Backup
DoCmd.RunCommand acCmdSaveRecord
Exit_CmdSave_Click:
Exit Sub
Err_CmdSave_Click:
MsgBox Err.Description
Resume Exit_CmdSave_Click
End If
End Sub
Public Sub Master_Asset_Backup()
Dim SQLqry As String
DoCmd.SetWarnings False
SQLqry = "INSERT INTO [Master Asset Backup] "
SQLqry = SQLqry & "([Rpt Asset ID], [Report Name], [Report Description]"
If Not Me.Business_use = Null Then SQLqry = SQLqry & ", [Business Uses]"
SQLqry = SQLqry & ") VALUES ("
SQLqry = SQLqry & Rpt_Asset_IDV & ", " & Report_NameV & ", " & Report_DescriptionV
If Me.Business_use = Not Null Then SQLqry = SQLqry & ", " & Business_ValueV
Debug.Print SQLqry
DoCmd.RunSQL SQLqry
DoCmd.SetWarnings True
End Sub
There's a lot more, but it's all very repetitive. The SQL I'm getting is (shortened) this:
INSERT INTO [Master Asset Backup] ([Rpt Asset ID], [Report Name], [Report Description]) VALUES (89, Customer Report, This report is for customers to compare our services);
I've checked for special characters and found none, and as you can see it's ignoring my If Then about Business Uses (And all the other fields), and still not running the SQL. Help?
Option Compare Database
Dim Rpt_Asset_IDV As Integer
Dim Report_NameV As String
Dim Report_DescriptionV As String
Dim Business_ValueV As String
Private Sub cmdSave_Click()
If MsgBox("Saving the changes will update the record. Are you sure you wish to save?", vbYesNo) = vbYes Then
Rpt_Asset_IDV = Me.Rpt_Asset_ID.Value
Report_NameV = Me.Report_Name.Value
Report_DescriptionV = Me.Report_Description.Value
If Not IsNull(Me.Business_use) Then BusinessValueV = Me.Business_use.Value
Call Master_Asset_Backup
DoCmd.RunCommand acCmdSaveRecord
Exit_CmdSave_Click:
Exit Sub
Err_CmdSave_Click:
MsgBox Err.Description
Resume Exit_CmdSave_Click
End If
End Sub
Public Sub Master_Asset_Backup()
Dim SQLqry As String
DoCmd.SetWarnings False
SQLqry = "INSERT INTO [Master Asset Backup] "
SQLqry = SQLqry & "([Rpt Asset ID], [Report Name], [Report Description]"
If Not Me.Business_use = Null Then SQLqry = SQLqry & ", [Business Uses]"
SQLqry = SQLqry & ") VALUES ("
SQLqry = SQLqry & Rpt_Asset_IDV & ", " & Report_NameV & ", " & Report_DescriptionV
If Me.Business_use = Not Null Then SQLqry = SQLqry & ", " & Business_ValueV
Debug.Print SQLqry
DoCmd.RunSQL SQLqry
DoCmd.SetWarnings True
End Sub
There's a lot more, but it's all very repetitive. The SQL I'm getting is (shortened) this:
INSERT INTO [Master Asset Backup] ([Rpt Asset ID], [Report Name], [Report Description]) VALUES (89, Customer Report, This report is for customers to compare our services);
I've checked for special characters and found none, and as you can see it's ignoring my If Then about Business Uses (And all the other fields), and still not running the SQL. Help?