Nmacp Level: Guest

|
Errors on trying to add data
Hi everyone. Can someone help me please? I've written a database that's updateable from vb. My problem is that in one area i can't update the table from the form. I get the errors 3705 and 94 which say that the object's already open and i have a null value.I can't figure out why i've got the problem. The errors are in SubDisplaySoftUsersData this is referencing data from UpdateCompSoft Details and should run when running frmUpdateApp(frmSoftApp.frm)
I've included all this code. Thanx in anticipation
Option Explicit
Public dbSoftware As Connection
Public rsCompSoft As Recordset
Public rsEmployee As Recordset
Public rsCompare As Recordset
Public UsingSoftware As Long 'by definition the autonumber is long thats why you make it a long'
Sub Main()
frmUpdateApp.Show
End Sub
Sub InitialiseEmployeeData()
frmUpdateEmployee.txtEmployeeID = ""
frmUpdateEmployee.txtFirstName = ""
frmUpdateEmployee.txtLastName = ""
End Sub
Sub InitialiseCompSoftData()
frmUpdateCompSoft.txtSoftwareID = ""
frmUpdateCompSoft.txtSoftwareName = ""
End Sub
Sub DisplayEmployeeData()
frmUpdateEmployee.txtEmployeeID = rsEmployee("EmployeeID")
frmUpdateEmployee.txtFirstName = rsEmployee("FirstName")
frmUpdateEmployee.txtLastName = rsEmployee("LastName")
End Sub
Sub DisplayCompSoftData()
frmUpdateCompSoft.txtSoftwareID = rsCompSoft("SoftwareID")
frmUpdateCompSoft.txtSoftwareName = rsCompSoft("SoftwareName")
End Sub
Sub DisplaySoftUsersData()
frmUpdateSoftwareUser.txtEmployeeID = rsEmployee("EmployeeID")
frmUpdateSoftwareUser.txtLastName = rsEmployee("LastName")
frmUpdateSoftwareUser.txtFirstName = rsEmployee("FirstName")
frmUpdateSoftwareUser.txtSoftwareID = rsCompSoft("SoftwareID")
test:
MsgBox (Str(Err.Number))
'Complaining:Object already open & of null value as the
'text entered isn't contained in database
frmUpdateSoftwareUser.txtSoftwareName = rsCompSoft("SoftwareName")
Call OpenCompareQuery 'Opens a query from the database SQL'
If rsCompare.RecordCount > 0 Then 'means that an employee record is greater than 0 and an employee has been found'
frmUpdateSoftwareUser.txtUseSoft = "Yes"
UsingSoftware = rsCompare("Sequence") 'Saved the sequence'
frmUpdateSoftwareUser.cmdChangeSoftUsage.Caption = "Using Software"
Else
frmUpdateSoftwareUser.txtUseSoft = "No" 'if no add a caption add Employed'
frmUpdateSoftwareUser.cmdChangeSoftUsage.Caption = "Not Using Software"
End If
Call CloseCompareQuery
End Sub
Sub WriteEmployeeData()
rsEmployee("EmployeeID") = frmUpdateEmployee.txtEmployeeID
rsEmployee("LastName") = frmUpdateEmployee.txtLastName
rsEmployee("FirstName") = frmUpdateEmployee.txtFirstName
End Sub
Sub WriteCompSoftData()
rsCompSoft("SoftwareID") = frmUpdateSoftwareUser.txtSoftwareID
rsCompSoft("SoftwareName") = frmUpdateSoftwareUser.txtSoftwareName
End Sub
Sub OpenEmployeeTable()
rsEmployee.Open "Employee", _
dbSoftware, adOpenStatic, adLockOptimistic, adCmdTableDirect
End Sub
Sub OpenCompSoftTable()
On Error GoTo test
rsCompSoft.Open "CompSoft", _
dbSoftware, adOpenStatic, adLockOptimistic, adCmdTableDirect
test:
MsgBox (Str(Err.Number))
'The operation requested by the application is not allowed
'if the object is open.
End Sub
Sub OpenCompareTable()
rsCompare.Open "SoftUsers", _
dbSoftware, adOpenStatic, adLockOptimistic, adCmdTableDirect
End Sub
Sub OpenCompareQuery()
Dim SQLStr As String
SQLStr = "SELECT * FROM [SoftUsers] " & _
"WHERE [EmployeeID] = '" & rsEmployee("EmployeeID") & "' " & _
"AND [SoftwareID] = '" & rsCompSoft("SoftwareID") & "'"
rsCompare.Open SQLStr, _
dbSoftware, adOpenStatic, adLockOptimistic
End Sub
Sub OpenDatabase()
Set dbSoftware = New ADODB.Connection
dbSoftware.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=Software.mdb;"
Set rsCompSoft = New Recordset 'set means create objects but do nothing with them'
Set rsEmployee = New Recordset
Set rsCompare = New Recordset
End Sub
Sub CloseEmployeeTable()
rsEmployee.Close
End Sub
Sub CloseCompSoftTable()
rsCompSoft.Close
End Sub
Sub CloseCompareTable()
rsCompare.Close
End Sub
Sub CloseCompareQuery()
rsCompare.Close
End Sub
Sub CloseDatabase()
dbSoftware.Close
Set dbSoftware = Nothing 'removes object from memory'
Set rsCompSoft = Nothing
Set rsEmployee = Nothing
Set rsCompare = Nothing
End Sub
---------------------------------------
Option Explicit
Private Sub cmdAdd_Click()
Call InitialiseCompSoftData
cmdUpdate.Caption = "Save Details"
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdNext_Click()
rsCompSoft.MoveNext
If Not rsCompSoft.EOF Then
Call DisplayCompSoftData
Else
MsgBox ("End of file")
rsCompSoft.MoveLast
End If
End Sub
Private Sub cmdPrevious_Click()
rsCompSoft.MovePrevious
If Not rsCompSoft.BOF Then
Call DisplayCompSoftData
Else
MsgBox ("Beginning of file")
rsCompSoft.MoveFirst
End If
End Sub
Private Sub cmdUpdate_Click()
If cmdUpdate.Caption = "Save details" Then
Call WriteCompSoftData
rsCompSoft.Update
Else
rsCompSoft.AddNew
Call WriteCompSoftData
rsCompSoft.Update
cmdUpdate.Caption = "Update"
End If
End Sub
Private Sub Form_Load()
Me.Left = 700
Me.Top = 200
Call OpenCompSoftTable
Call DisplayCompSoftData
frmUpdateApp.mnuFile.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
frmUpdateApp.mnuFile.Enabled = True
Call CloseCompSoftTable
End Sub
---------------------------------------
Option Explicit
Private Sub MDIForm_Load()
Call OpenDatabase
End Sub
Private Sub mnuExit_Click()
Call CloseDatabase
Unload Me
End Sub
Private Sub mnuUpdateSoftwareUsers_Click()
frmUpdateSoftwareUser.Show
End Sub
Private Sub mnuUpdateEmployeeData_Click()
frmUpdateEmployee.Show
End Sub
Private Sub mnuUpdateCompanySoftware_Click()
frmUpdateCompSoft.Show
End Sub
|