R
rbain
I have a form which I am using to move some records from the office inventory
to the warehouse inventory. Each inventory has two tables (tblAuditBox,
tblAuditRecords) and (tblAuditOfficeBox, tblAuditOfficeRecords).
My form is designed to allow the user to select records from a combo box,
supply a new box number, specify a record type and then to create the new box
and fill it with the selected records.
When I click the btn_Move I get a run time error: -2147217867 (80040e35)
'RecordID' is not an index in this table. Debug highligts the line that
creates the index:
rstAuditOffice.Index = "RecordID"
I read kba: 287459, but I'm still having the same error message. I have
verified ADOX 2.1 is checked in references.
The function ValidateBoxNum() is a custom function that checks to see if the
new box number already exists in the tblAuditBox and returns a Boolean value.
Would appreciate any help. Code for btn_Move is listed below:
Private Sub btnMove_Click()
Dim rstAuditOffice As New ADODB.Recordset
Dim rstNewBox As New ADODB.Recordset
Dim intNumSelected As Integer
Dim conn As ADODB.Connection
Dim varItm As Variant
Dim strSQLInsertBox As String
Dim intRecordType As Integer
Dim intBoxID As Integer
Dim intBoxAutoID As Integer
intBoxID = CInt(Me!txtNewBoxNum.Value)
intRecordType = Me!intRecordType.Value
'Define connection
Set conn = CurrentProject.Connection
'Debug.Print conn.ConnectionString
If ValidateBoxNum(txtNewBoxNum.Value) Then
'Build SQL statement to add a new box
strSQLInsertBox = "INSERT INTO tblAuditBox (BoxID,DepartmentID,TypeID)"
strSQLInsertBox = strSQLInsertBox & " VALUES (" & intBoxID & ",6," &
intRecordType & ");"
'Add new box
conn.Execute strSQLInsertBox
rstNewBox.Open "Select Max(BoxAuto) as MaxAuto from tblAuditBox", conn
intBoxAutoID = rstNewBox("MaxAuto")
Set rstNewBox = Nothing
'Verify that items are selected
intNumSelected = Me.list_office_records.ItemsSelected.Count
If Nz(intNumSelected) = 0 Then
MsgBox ("You must select at least one record.")
Exit Sub
End If
'Open tblAuditRecordsOffice
rstAuditOffice.Open "tblAuditRecordsOffice", conn, adOpenKeyset,
adLockOptimistic, _
adCmdTableDirect
'Begin transaction
conn.BeginTrans
'******
'
rstAuditOffice.Index = "RecordID"
'
'******
For Each varItm In Me.list_office_records.ItemsSelected
'Find record in tblAuditRecordsOffice
rstAuditOffice.Seek list_office_records.ItemData(varItm)
'Update it with new box number and auto box number
rstAuditOffice!BoxID = intBoxID
rstAuditOffice!AutoBox = intBoxAutoID
rstAuditOffice.Update
Next varItm
conn.CommitTrans
Else
txtNewBoxNum.SetFocus
btnMove.Enabled = False
End If
End Sub
Thanks,
RCB
to the warehouse inventory. Each inventory has two tables (tblAuditBox,
tblAuditRecords) and (tblAuditOfficeBox, tblAuditOfficeRecords).
My form is designed to allow the user to select records from a combo box,
supply a new box number, specify a record type and then to create the new box
and fill it with the selected records.
When I click the btn_Move I get a run time error: -2147217867 (80040e35)
'RecordID' is not an index in this table. Debug highligts the line that
creates the index:
rstAuditOffice.Index = "RecordID"
I read kba: 287459, but I'm still having the same error message. I have
verified ADOX 2.1 is checked in references.
The function ValidateBoxNum() is a custom function that checks to see if the
new box number already exists in the tblAuditBox and returns a Boolean value.
Would appreciate any help. Code for btn_Move is listed below:
Private Sub btnMove_Click()
Dim rstAuditOffice As New ADODB.Recordset
Dim rstNewBox As New ADODB.Recordset
Dim intNumSelected As Integer
Dim conn As ADODB.Connection
Dim varItm As Variant
Dim strSQLInsertBox As String
Dim intRecordType As Integer
Dim intBoxID As Integer
Dim intBoxAutoID As Integer
intBoxID = CInt(Me!txtNewBoxNum.Value)
intRecordType = Me!intRecordType.Value
'Define connection
Set conn = CurrentProject.Connection
'Debug.Print conn.ConnectionString
If ValidateBoxNum(txtNewBoxNum.Value) Then
'Build SQL statement to add a new box
strSQLInsertBox = "INSERT INTO tblAuditBox (BoxID,DepartmentID,TypeID)"
strSQLInsertBox = strSQLInsertBox & " VALUES (" & intBoxID & ",6," &
intRecordType & ");"
'Add new box
conn.Execute strSQLInsertBox
rstNewBox.Open "Select Max(BoxAuto) as MaxAuto from tblAuditBox", conn
intBoxAutoID = rstNewBox("MaxAuto")
Set rstNewBox = Nothing
'Verify that items are selected
intNumSelected = Me.list_office_records.ItemsSelected.Count
If Nz(intNumSelected) = 0 Then
MsgBox ("You must select at least one record.")
Exit Sub
End If
'Open tblAuditRecordsOffice
rstAuditOffice.Open "tblAuditRecordsOffice", conn, adOpenKeyset,
adLockOptimistic, _
adCmdTableDirect
'Begin transaction
conn.BeginTrans
'******
'
rstAuditOffice.Index = "RecordID"
'
'******
For Each varItm In Me.list_office_records.ItemsSelected
'Find record in tblAuditRecordsOffice
rstAuditOffice.Seek list_office_records.ItemData(varItm)
'Update it with new box number and auto box number
rstAuditOffice!BoxID = intBoxID
rstAuditOffice!AutoBox = intBoxAutoID
rstAuditOffice.Update
Next varItm
conn.CommitTrans
Else
txtNewBoxNum.SetFocus
btnMove.Enabled = False
End If
End Sub
Thanks,
RCB