ReaperFett
04-16-2004, 03:43 AM
Okay, I want to have a simple system where two listboxes interact. One shows the MemberID, Forename and Surname from Member and the other shows BookID and title. When you select something from each list, you can click add loan and it will use a table called Loan and add the MemberID and BookIDs to columns (They are made via AutoNumber in Access, they save to a number datatype), and then input today's date. The idea is I can then use this table with foreign keys to show the full details in that relationship.
However, when ever I attempt a loan, it gibes me an error saying "Run-time error '3420': Object invalid or no longer set", highlighting "rs3!MemberID = rs!MemberID" in Private Sub MakeLoanButton_Click().
Basically, what am I doing wrong? All I need is the relevent ID.
As an aside, is there any way to make it so that a message popup appears if you try and add a loan when you haven't selected from both columns, stopping it from adding?
The code follows:
Private Sub Form_Load()
Set MyDataBase = OpenDatabase(App.Path & "\Library.mdb")
Set rs = MyDataBase.OpenRecordset("select * from Member Order by MemberID")
Set rs2 = MyDataBase.OpenRecordset("Book")
Set rs3 = MyDataBase.OpenRecordset("Loan")
Do While Not rs.EOF
MemberList.AddItem rs!MemberID & " - " & rs!Forename & " " & rs!Surname
rs.MoveNext
Loop
rs.Close
Do While Not rs2.EOF
BookList.AddItem rs2!BookID & " - " & rs2!BookName
rs2.MoveNext
Loop
rs2.Close
End Sub
Private Sub MakeLoanButton_Click()
Reply = MsgBox("Are you sure you wish to make this loan?", 1, "Make Loan?")
If Reply = 1 Then
rs3.AddNew
rs3!MemberID = rs!MemberID
rs3!BookID = rs2!BookID
rs3!DateStarted = DateSerial(Year(Date), Month(Date), Day(Date))
rs3.Update
Exit Sub
End If
End Sub
Thanks in advance :)
However, when ever I attempt a loan, it gibes me an error saying "Run-time error '3420': Object invalid or no longer set", highlighting "rs3!MemberID = rs!MemberID" in Private Sub MakeLoanButton_Click().
Basically, what am I doing wrong? All I need is the relevent ID.
As an aside, is there any way to make it so that a message popup appears if you try and add a loan when you haven't selected from both columns, stopping it from adding?
The code follows:
Private Sub Form_Load()
Set MyDataBase = OpenDatabase(App.Path & "\Library.mdb")
Set rs = MyDataBase.OpenRecordset("select * from Member Order by MemberID")
Set rs2 = MyDataBase.OpenRecordset("Book")
Set rs3 = MyDataBase.OpenRecordset("Loan")
Do While Not rs.EOF
MemberList.AddItem rs!MemberID & " - " & rs!Forename & " " & rs!Surname
rs.MoveNext
Loop
rs.Close
Do While Not rs2.EOF
BookList.AddItem rs2!BookID & " - " & rs2!BookName
rs2.MoveNext
Loop
rs2.Close
End Sub
Private Sub MakeLoanButton_Click()
Reply = MsgBox("Are you sure you wish to make this loan?", 1, "Make Loan?")
If Reply = 1 Then
rs3.AddNew
rs3!MemberID = rs!MemberID
rs3!BookID = rs2!BookID
rs3!DateStarted = DateSerial(Year(Date), Month(Date), Day(Date))
rs3.Update
Exit Sub
End If
End Sub
Thanks in advance :)