Hi Steve
Nothing really shone out to me as being wrong either. But
in answer to your question, the Borrower Number is always
in the right place. What confuses me is that the error
comes up even though the field is always populated.
Let me explain the connection between the recordsets, code
and subform. My program has a front end (frmControl),
which contains:
- a list box(List0): the rowsource property of list box
object variable set to Acquisition Number, ISBN, Title,
Author, Category;
- a text box(Text2);
- a command button (Command4); and
- a subform (fsubControl): the fields are
lngAcquisitionNumberCnt, strISBN, strTitle, strAuthor,
strCategory, dtmDateBorrowed, chkReserve and chkBorrow.
As you may tell, it is a library database. To use
frmControl a user selects an option in the list
box, types in a search string in the text box, clicks the
command button [this populates the subform] and clicks the
check boxes to Reserve or Borrow. When i click reserve or
Borrow [this brings up an input box requesting Borrower
Number] and then try to move to a new record, the program
freezes and the error message appears. The code for these
are(with a brief description of the tables):
- tblLoanRelation (lngBorrowerNumberCnt,
lngAcquisitionNumberCnt, dtmDateReserved, dtmDateBorrowed,
chkReserve, chkBorrow).
NB. lngAcquisitionNumberCnt is a unique number assigned to
a book. Together with lngBorrowerNumberCnt, these make a
composite primary key.
- tblAcquisitionRelation (lngAcquisitionNumberCnt,
strISBN, dtmDateAcquired)
NB. There can be duplicate copies of a book
- tblBookRelation (strISBN, strTitle, strAuthor,
strCategory).
- tblBorrowerRelation (lngBorrowerNumberCnt,
strBorrowerName).
Private Sub Borrow_Click()
' Purpose: To populate tblLoanRelation
On Error GoTo Err_Borrow_Click
Dim recSubFormRecordSource As Recordset
Dim recBorrowerRelation As Recordset
Dim recLoanRelation As Recordset
Dim dbshigham As Database
Dim lngCurrentRecord As Long
Dim intLoop As Integer
Dim lngAcquisitionNumber As Long
Dim lngBorrowerNumber As Long
Set dbshigham = DBEngine(0)(0)
Set recSubFormRecordSource = dbshigham.OpenRecordset
(Me.Form.RecordSource)
lngCurrentRecord = Me.CurrentRecord
' Obtain the Acquisition Number of the record being checked
Do Until recSubFormRecordSource.EOF = True
intLoop = intLoop + 1
If intLoop = lngCurrentRecord Then
lngAcquisitionNumber = recSubFormRecordSource(0)
Exit Do
Else
recSubFormRecordSource.MoveNext
End If
Loop
' Verify Borrower Number
lngBorrowerNumber = InputBox("Please enter your borrower
Number")
Set recBorrowerRelation = dbshigham.OpenRecordset
("tblBorrowerRelation")
Do Until recBorrowerRelation.EOF = True
If recBorrowerRelation(0) = lngBorrowerNumber Then
Exit Do
Else
recBorrowerRelation.MoveNext
If recBorrowerRelation.EOF Then
MsgBox "This Borrower Number does not exist!"
Exit Sub
End If
End If
Loop
' Update tblLoanRelation
Set recLoanRelation = dbshigham.OpenRecordset
("tblLoanRelation", dbOpenDynaset)
recLoanRelation.AddNew
recLoanRelation(0) = lngBorrowerNumber
recLoanRelation(1) = lngAcquisitionNumber
recLoanRelation(3) = Date
recLoanRelation.Update
MsgBox "This is confirmation that Borrower Number " &
lngBorrowerNumber & " has borrowed " & _
"Acquisition Number " & lngAcquisitionNumber
Exit_Borrow_Click:
Exit Sub
Err_Borrow_Click:
MsgBox Err.Number & " " & Err.Description
Resume Exit_Borrow_Click
End Sub
Private Sub Reserve_Click()
' Purpose: To populate tblLoanRelation
Dim recSubFormRecordSource As Recordset
Dim recBorrowerRelation As Recordset
Dim recLoanRelation As Recordset
Dim dbshigham As Database
Dim lngCurrentRecord As Long
Dim intLoop As Integer
Dim lngAcquisitionNumber As Long
Dim lngBorrowerNumber As Long
On Error GoTo Err_Reserve_Click
Set dbshigham = DBEngine(0)(0)
Set recSubFormRecordSource = dbshigham.OpenRecordset
(Me.Form.RecordSource)
lngCurrentRecord = Me.CurrentRecord
' Obtain the Acquisition Number of the record being checked
Do Until recSubFormRecordSource.EOF = True
intLoop = intLoop + 1
If intLoop = lngCurrentRecord Then
lngAcquisitionNumber = recSubFormRecordSource(0)
Exit Do
Else
recSubFormRecordSource.MoveNext
End If
Loop
' Verify the Borrower Number
lngBorrowerNumber = InputBox("Please enter your borrower
Number")
Set recBorrowerRelation = dbshigham.OpenRecordset
("tblBorrowerRelation")
Do Until recBorrowerRelation.EOF = True
If recBorrowerRelation(0) = lngBorrowerNumber Then
Exit Do
Else
recBorrowerRelation.MoveNext
If recBorrowerRelation.EOF Then
MsgBox "This Borrower Number does not exist!"
Exit Sub
End If
End If
Loop
' Update tblLoanRelation
Set recLoanRelation = dbshigham.OpenRecordset
("tblLoanRelation", dbOpenDynaset)
recLoanRelation.AddNew
recLoanRelation(0) = lngBorrowerNumber
recLoanRelation(1) = lngAcquisitionNumber
recLoanRelation(2) = Date
recLoanRelation.Update
MsgBox "This is confirmation that Borrower Number " &
lngBorrowerNumber & " has reserved " & _
"Acquisition Number " & lngAcquisitionNumber
Exit_Reserve_Click:
Exit Sub
Err_Reserve_Click:
MsgBox Err.Number & " " & Err.Description
Resume Exit_Reserve_Click
End Sub
Any help would be appreciated. Thanks for your ongoing
help, Steve.
Martin