D
Dan @BCBS
This code behind a command button should check to see if a record exists and
open a form with that data if it does. If record does not exist it will open
the form in data entry mode.
I don't understand this error???
Private Sub cmdMember_Click()
On Error GoTo Err_cmdMember_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim dbcurrent As DAO.Database
Dim rstemp As DAO.Recordset
If IsNull([cmdMember]) Then
MsgBox "Please enter a Member # before proceeding."
Exit Sub
Else
'Check to see if a record already exists
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from [tblMemberInfo]
where [MemberNo] = " & "'" & Me.[cmdMember] & "'" & ";")
stDocName = "f_MemberSub"
If rstemp.RecordCount > 0 Then 'Open Record
stLinkCriteria = "[MemberNo]=" & "'" & Me.[cmdMember] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else 'Create a new record
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!f_MemberSub.DataEntry = True
End If
Forms!f_MemberSub.MemberNo = Me.cmdMember
End If
Exit_cmdMember_Click:
Exit Sub
Err_cmdMember_Click:
MsgBox Err.Description
Resume Exit_cmdMember_Click
End Sub
open a form with that data if it does. If record does not exist it will open
the form in data entry mode.
I don't understand this error???
Private Sub cmdMember_Click()
On Error GoTo Err_cmdMember_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim dbcurrent As DAO.Database
Dim rstemp As DAO.Recordset
If IsNull([cmdMember]) Then
MsgBox "Please enter a Member # before proceeding."
Exit Sub
Else
'Check to see if a record already exists
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from [tblMemberInfo]
where [MemberNo] = " & "'" & Me.[cmdMember] & "'" & ";")
stDocName = "f_MemberSub"
If rstemp.RecordCount > 0 Then 'Open Record
stLinkCriteria = "[MemberNo]=" & "'" & Me.[cmdMember] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else 'Create a new record
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!f_MemberSub.DataEntry = True
End If
Forms!f_MemberSub.MemberNo = Me.cmdMember
End If
Exit_cmdMember_Click:
Exit Sub
Err_cmdMember_Click:
MsgBox Err.Description
Resume Exit_cmdMember_Click
End Sub