Open form to record with button on current form

Paul Clark

Registered User.
Local time
Today, 13:18
Joined
Oct 30, 2011
Messages
23
I have a button on form Membership with ID [Membership_No] and trying to open "frm_gmem" with ID [GMembership_No] at the current record.

The preceeding If msg works as expected but if false brings up Enter Parameter Value prompt for GMembership_No

Left blank or given an ID number, it still opens to a blank record.
Tried it with and without []

Code:
Private Sub cmd_gmem_Click()
     If (Me.Status <> "C") And (Me.Status <> "P") Then
         MsgBox ("Only Status P or C are valid for Group Members")
      Else
DoCmd.OpenForm "frm_gmem", , , "[GMembership_No]= '" & Me!Membership_No & "'"
    End If
End Sub
 
Try this - as an explanation using <> will not include null values.
Code:
Private Sub cmd_gmem_Click()
     If  IsNull(Me.Status) OR (Me.Status <> "C" And Me.Status <> "P") Then
         MsgBox "Only Status P or C are valid for Group Members"
         Exit Sub
     End If

     DoCmd.OpenForm "frm_gmem", , , "[GMembership_No]= '" & 
     Me!Membership_No & "'"
    
End Sub
 
Thanks Minty but that's not the problem.
It is the OpenForm 'where' condition that is not working.

Status is never Null and that part of the If statement is working correctly.
 
If Gmembrship_no is numeric remove the two single quotes.
 
Sorted = [Membership_No] = is the table field name Not the form field name [GMembership_No], and yes, then it was type missmatch.

Code:
Private Sub cmd_gmem_Click()

      ' Looks for any record for this MembershipNo where MembershipNo. match'
     If (Me.Status <> "C") And (Me.Status <> "P") Then
         MsgBox ("Only Status P or C are valid for Group Members")
          Else
   DoCmd.OpenForm "frm_gmem", , , "[Membership_No]= " & Me![Membership_No]
    End If
End Sub
Thanks
 

Users who are viewing this thread

Back
Top Bottom