F
ftrujill0
Hi,
I'm totally new with VBA so please forgive my ignorance.... I am getting a
'Run Time Error: 7874 Microsoft Office Access can't find object; #" when
trying to call a function that creates the next value in a custom counter. It
appears to be working fine (validation is working and data is loaded into the
table) except that the run time error appears at the end when its not finding
the object and asks if I want to debug.....
I have placed the function within a sub procedure that is fired when a
submit button is clicked. The sub procedures determines if a checkbox is
checked and runs a SQL insert statement if the box is true and then calls the
counter function to update the counter value. The counter function works
fine when I call it in the onClick line (=Next_Custom_Counter() ) but not
when nested in the sub procedure.
Here is my code....
Here is the Next_Custom_Counter function Code (taken from MS website):
Option Compare Database
Function Next_Custom_Counter()
On Error GoTo Next_Custom_Counter_Err
Dim MyDB As Database
Dim MyTable As Recordset
Dim NextCounter As Long
Set MyDB = CurrentDb
Set MyTable = MyDB.OpenRecordset("COUNTER")
MyTable.Edit
NextCounter = MyTable("Next Available Counter")
MyTable("Next Available Counter") = NextCounter + 1
MyTable.Update
MsgBox "The selected files have been assigned to group: " & "G" &
Str$(NextCounter)
Next_Custom_Counter = NextCounter
Exit Function
Next_Custom_Counter_Err:
MsgBox "Error " & Err & ": " & Error$
If Err <> 0 Then Resume
End
End Function
Here is the sub procedure that I am trying to call:
Private Sub Command20_Click()
DoCmd.SetWarnings False
If newgroup = True Then
DoCmd.RunSQL "INSERT INTO SF135 ( GROUPNUMBER, FOLDERID, BOX, BOXOF,
DISPOSALDT, FRC_RESTRICTION ) SELECT [counter].[groupid] & [next available
counter] AS GroupNumber, SF135_TEMP.FOLDERID,
Format([Forms]![SF135_PREPARE_FILES02]![boxof]) AS box,
Format([Forms]![SF135_PREPARE_FILES02]![Box]) AS boxof,
Format([Forms]![SF135_PREPARE_FILES02]![DisposalDT]) AS disposaldt,
Format([Forms]![SF135_PREPARE_FILES02]![DisposalRestrictCode]) AS restriction
FROM SF135_TEMP, [Counter] WHERE (((SF135_TEMP.ADD)=True) AND
(([Forms]![SF135_PREPARE_FILES02]![newgroup])=True));"
DoCmd.OpenFunction Next_Custom_Counter()
DoCmd.Close
Else
DoCmd.RunSQL "INSERT INTO SF135 ( GROUPNUMBER, FOLDERID, BOX, BOXOF,
DISPOSALDT, FRC_RESTRICTION ) SELECT Forms!SF135_PREPARE_FILES02!groupid AS
GroupNumber2, SF135_TEMP.FOLDERID, Format(Forms!SF135_PREPARE_FILES02!boxof)
AS box, Format(Forms!SF135_PREPARE_FILES02!Box) AS boxof,
Format(Forms!SF135_PREPARE_FILES02!DisposalDT) AS disposaldt,
Format(Forms!SF135_PREPARE_FILES02!DisposalRestrictCode) AS restriction FROM
SF135_TEMP WHERE (((SF135_TEMP.ADD)=True) And
((Forms!SF135_PREPARE_FILES02!oldgroup)=True));"
DoCmd.Close
End If
End Sub
THANK YOU!!!!!
I'm totally new with VBA so please forgive my ignorance.... I am getting a
'Run Time Error: 7874 Microsoft Office Access can't find object; #" when
trying to call a function that creates the next value in a custom counter. It
appears to be working fine (validation is working and data is loaded into the
table) except that the run time error appears at the end when its not finding
the object and asks if I want to debug.....
I have placed the function within a sub procedure that is fired when a
submit button is clicked. The sub procedures determines if a checkbox is
checked and runs a SQL insert statement if the box is true and then calls the
counter function to update the counter value. The counter function works
fine when I call it in the onClick line (=Next_Custom_Counter() ) but not
when nested in the sub procedure.
Here is my code....
Here is the Next_Custom_Counter function Code (taken from MS website):
Option Compare Database
Function Next_Custom_Counter()
On Error GoTo Next_Custom_Counter_Err
Dim MyDB As Database
Dim MyTable As Recordset
Dim NextCounter As Long
Set MyDB = CurrentDb
Set MyTable = MyDB.OpenRecordset("COUNTER")
MyTable.Edit
NextCounter = MyTable("Next Available Counter")
MyTable("Next Available Counter") = NextCounter + 1
MyTable.Update
MsgBox "The selected files have been assigned to group: " & "G" &
Str$(NextCounter)
Next_Custom_Counter = NextCounter
Exit Function
Next_Custom_Counter_Err:
MsgBox "Error " & Err & ": " & Error$
If Err <> 0 Then Resume
End
End Function
Here is the sub procedure that I am trying to call:
Private Sub Command20_Click()
DoCmd.SetWarnings False
If newgroup = True Then
DoCmd.RunSQL "INSERT INTO SF135 ( GROUPNUMBER, FOLDERID, BOX, BOXOF,
DISPOSALDT, FRC_RESTRICTION ) SELECT [counter].[groupid] & [next available
counter] AS GroupNumber, SF135_TEMP.FOLDERID,
Format([Forms]![SF135_PREPARE_FILES02]![boxof]) AS box,
Format([Forms]![SF135_PREPARE_FILES02]![Box]) AS boxof,
Format([Forms]![SF135_PREPARE_FILES02]![DisposalDT]) AS disposaldt,
Format([Forms]![SF135_PREPARE_FILES02]![DisposalRestrictCode]) AS restriction
FROM SF135_TEMP, [Counter] WHERE (((SF135_TEMP.ADD)=True) AND
(([Forms]![SF135_PREPARE_FILES02]![newgroup])=True));"
DoCmd.OpenFunction Next_Custom_Counter()
DoCmd.Close
Else
DoCmd.RunSQL "INSERT INTO SF135 ( GROUPNUMBER, FOLDERID, BOX, BOXOF,
DISPOSALDT, FRC_RESTRICTION ) SELECT Forms!SF135_PREPARE_FILES02!groupid AS
GroupNumber2, SF135_TEMP.FOLDERID, Format(Forms!SF135_PREPARE_FILES02!boxof)
AS box, Format(Forms!SF135_PREPARE_FILES02!Box) AS boxof,
Format(Forms!SF135_PREPARE_FILES02!DisposalDT) AS disposaldt,
Format(Forms!SF135_PREPARE_FILES02!DisposalRestrictCode) AS restriction FROM
SF135_TEMP WHERE (((SF135_TEMP.ADD)=True) And
((Forms!SF135_PREPARE_FILES02!oldgroup)=True));"
DoCmd.Close
End If
End Sub
THANK YOU!!!!!