open form with where conditioning

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pjawynn
    New Member
    • Jun 2013
    • 1

    #1

    open form with where conditioning

    Good Morning

    Have the following code and is all working but I need to add an additional section to the where clause but cannot get it to work I need to add to both dcounts [log Number] = me![Log Number] any ideas

    Code:
    Private Sub Submit_Click()
    If IsNull(Me.Serial_Number) = True Or IsNull(Me.Log_Number) Or IsNull(Me.Type_of_Incident) = True Then
    MsgBox "Feilds cannot be Left Blank"
         
    Exit Sub
    End If
    
    
    If DCount("*", Me![type of incident], "[serial number] = """ & Me![serial Number] & """") = 1 Then GoTo openform
    If DCount("*", Me![type of incident], "[serial Number] = """ & Me![serial Number] & """") = 0 Then GoTo Error1
    
    Error1:
    MsgBox "Incident does not exist Please check you inputted Data and try again", , "Report Does Not Exist"
    Exit Sub
    
    openform:
    DoCmd.openform Me.Type_of_Incident, , , "[Serial Number]='" & Me![serial Number] & "' and [Log Number]='" & Me![log Number] & "'"
    
    DoCmd.Close acForm, "continue report", acSaveNo
    DoCmd.Close acForm, "Selection", acSaveNo
    
    End Sub
    Thank you
    Last edited by Rabbit; Jun 14 '13, 04:45 AM. Reason: Please use code tags when posting code.
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    First, there is no reason to run the DCount twice. Domain functions (any of the functions that start with D, ie. DCount, DLookup, DSum, etc.) all use lots of system resources. Instead, use the Select Case to test the value.

    As for the adding of the Log Number to the DCount criteria, just copy what you have in the DoCmd.OpenForm criteria as it looks correct assuming text fields and not number fields.

    Comment

    Working...