DogLover2006
Technical User
I have a form with a subform TempFederal on it and a button on it. On click of the button it creates a textbox and lable on the subform, it creates a table called NewYears and it also creates a new field in NewYears table. I also want the but to rename the table to Years, which is the table that the subform uses. But when I run my code I get the following error message:
Microsoft Jet database engine could not find the object. make sure the object exists and that you spelled it name and path name correct.
Here is my code:
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryCreateNewTable", acViewNormal
DoCmd.SetWarnings True
Call UpdateTable
DoCmd.RunMacro "RenameTable"
Dim frm As Form, ctlDefault As Control, ctlNew As Control
Dim intLtxt1 As Integer, intLeft, intTop1, intTop2, intNum, intSum, intNewLeft, intName
intLeft = 8760
intTop1 = 1140
intTop2 = 720
intSum = 10440 - 8760
intNum = intLeft + intSum
intLtxt1 = intNum
intNewLeft = intLeft + intSum + intSum
intName = Year(Now()) + 1
DoCmd.OpenForm "Temp_Federal", acDesign
Set frm = Forms!Temp_Federal
' Return Control object representing default Text box.
Set ctlDefault = frm.DefaultControl(acTextBox)
' Set some default properties.
With ctlDefault
.FontWeight = 700
.FontSize = 12
.Width = 1440
.Height = 300
.ControlSource = dbsTempFederal.TableDefs!Years!Fields(strName)
'dbsTempFederal.TableDefs!Years!Field(strName)
End With
' Create new text box.
Set ctlNew = CreateControl(frm.Name, acTextBox, , , , intLtxt1, intTop1)
' Set control's caption.
ctlNew.Name = intName
Set ctlDefault = frm.DefaultControl(acLabel)
' Set some default properties.
With ctlDefault
.FontWeight = 700
.FontSize = 12
.Width = 1440
.Height = 300
.TextAlign = 2
End With
' Create new lable.
Set ctlNew = CreateControl(frm.Name, acLabel, , , , intLtxt1, intTop2)
' Set control's caption.
ctlNew.Caption = intName
' Restore form.
DoCmd.Restore
DoCmd.RunMacro "saveform" 'this just close the form and subform and opens the form backup
Public Sub UpdateTable()
Dim dbsTempFederal As Database
Dim tdfNew As TableDef
Dim intName As Integer
Dim strName As String
intName = Year(Now()) + 1
strName = intName
Set dbsTempFederal = CurrentDb
' Create a new TableDef object.
Set tdfNew = dbsTempFederal.TableDefs!NewYears
' Add one new fields.
With tdfNew
.Fields.Append .CreateField(strName, dbDouble)
End With
dbsTempFederal.Close
DoCmd.Restore
End Sub
Please help and thank for your help
Microsoft Jet database engine could not find the object. make sure the object exists and that you spelled it name and path name correct.
Here is my code:
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryCreateNewTable", acViewNormal
DoCmd.SetWarnings True
Call UpdateTable
DoCmd.RunMacro "RenameTable"
Dim frm As Form, ctlDefault As Control, ctlNew As Control
Dim intLtxt1 As Integer, intLeft, intTop1, intTop2, intNum, intSum, intNewLeft, intName
intLeft = 8760
intTop1 = 1140
intTop2 = 720
intSum = 10440 - 8760
intNum = intLeft + intSum
intLtxt1 = intNum
intNewLeft = intLeft + intSum + intSum
intName = Year(Now()) + 1
DoCmd.OpenForm "Temp_Federal", acDesign
Set frm = Forms!Temp_Federal
' Return Control object representing default Text box.
Set ctlDefault = frm.DefaultControl(acTextBox)
' Set some default properties.
With ctlDefault
.FontWeight = 700
.FontSize = 12
.Width = 1440
.Height = 300
.ControlSource = dbsTempFederal.TableDefs!Years!Fields(strName)
'dbsTempFederal.TableDefs!Years!Field(strName)
End With
' Create new text box.
Set ctlNew = CreateControl(frm.Name, acTextBox, , , , intLtxt1, intTop1)
' Set control's caption.
ctlNew.Name = intName
Set ctlDefault = frm.DefaultControl(acLabel)
' Set some default properties.
With ctlDefault
.FontWeight = 700
.FontSize = 12
.Width = 1440
.Height = 300
.TextAlign = 2
End With
' Create new lable.
Set ctlNew = CreateControl(frm.Name, acLabel, , , , intLtxt1, intTop2)
' Set control's caption.
ctlNew.Caption = intName
' Restore form.
DoCmd.Restore
DoCmd.RunMacro "saveform" 'this just close the form and subform and opens the form backup
Public Sub UpdateTable()
Dim dbsTempFederal As Database
Dim tdfNew As TableDef
Dim intName As Integer
Dim strName As String
intName = Year(Now()) + 1
strName = intName
Set dbsTempFederal = CurrentDb
' Create a new TableDef object.
Set tdfNew = dbsTempFederal.TableDefs!NewYears
' Add one new fields.
With tdfNew
.Fields.Append .CreateField(strName, dbDouble)
End With
dbsTempFederal.Close
DoCmd.Restore
End Sub
Please help and thank for your help