rebeccabarker
Programmer
I am getting the following error message when I try to save a record in my access 2000 database: Object variable or With block variable not set. I have written VB behind a form to perform the save function.
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
Dim sSQL As String
Dim sEIN As String
Dim sEINFstHalf As String
Dim sEINLstHalf As String
Dim sDashPos As String
sDashPos = InStr(1, Me.txtEIN, "-")
sEINFstHalf = Mid(Me.txtEIN, 1, sDashPos - 1)
sEINLstHalf = Mid(Me.txtEIN, sDashPos + 1, 10)
sEIN = sEINFstHalf + sEINLstHalf
sSQL = "Select * from TBLEMPR where EMPREIN = '" & sEIN & "'"
'THE LINE BELOW IS CAUSING THE ERROR MESSAGE
rstTBLEMPR.Open sSQL, localConnection, adOpenDynamic, adLockOptimistic, adCmdTable
If rstTBLEMPR.EOF = False Then
With rstTBLEMPR
!Street = Me.txtStreet
!City = Me.txtCity
!State = Me.txtState
!ZipCode = Me.txtZip
!TELENO = Me.txtPhoneNum
!FAXNO = Me.txtFaxNo
.Update
.Close
End With
End If
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
I have searched all through google and none of the answers I found are helpful. I have save functions behind other forms that are identical to this one and are working fine.
Any help is greatly appreciated!
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
Dim sSQL As String
Dim sEIN As String
Dim sEINFstHalf As String
Dim sEINLstHalf As String
Dim sDashPos As String
sDashPos = InStr(1, Me.txtEIN, "-")
sEINFstHalf = Mid(Me.txtEIN, 1, sDashPos - 1)
sEINLstHalf = Mid(Me.txtEIN, sDashPos + 1, 10)
sEIN = sEINFstHalf + sEINLstHalf
sSQL = "Select * from TBLEMPR where EMPREIN = '" & sEIN & "'"
'THE LINE BELOW IS CAUSING THE ERROR MESSAGE
rstTBLEMPR.Open sSQL, localConnection, adOpenDynamic, adLockOptimistic, adCmdTable
If rstTBLEMPR.EOF = False Then
With rstTBLEMPR
!Street = Me.txtStreet
!City = Me.txtCity
!State = Me.txtState
!ZipCode = Me.txtZip
!TELENO = Me.txtPhoneNum
!FAXNO = Me.txtFaxNo
.Update
.Close
End With
End If
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
I have searched all through google and none of the answers I found are helpful. I have save functions behind other forms that are identical to this one and are working fine.
Any help is greatly appreciated!