user745778
user745778

Reputation: 97

How to open one form or another based on parameters?

Could someone please help me. This sounds simple but I'm at the point that I'm not sure if it can be done. The idea is: If parameters exist than open that record, else open a new one to enter data.

This is my attempt but I can't even get it to run yet.

Private Sub Form_Load()
    If (Me.Type = Act _
        and Me.Title <> null _
        and section <> null) _
        or Me.Type in ('Proposed','Final') 
        and Me.Rule <> null
    Then 
        Docmd.OpenForm "F_Eval" (but open that specific f_Eval)

    Else
        Docmd.OpenForm "F_NewEval" (to enter new record)
    End If
End Sub

Upvotes: 0

Views: 343

Answers (2)

HansUp
HansUp

Reputation: 97131

Revise your Null comparisons. As one example, consider this piece from your If condition:

Me.Title <> null

Nothing can ever be "not equal to" Null, same as nothing can ever be "equal to" Null. Not even another Null can be equal to Null (or not equal to Null).

So whether Me.Title is Null or contains a non-Null value, that expression will return Null. You want an expression which returns either True or False. Use the IsNull() function.

If Not IsNull(Me.Title) Then
   'do what you want for a non-Null Title here '
End If

For your "open that specific f_Eval" requirement, use the WhereCondition argument with the OpenForm Method. Here is an example copied from that linked page. It will open a form named Employees and restrict the form's record source to those rows where the LastName is "King".

DoCmd.OpenForm "Employees", , ,"LastName = 'King'"

So the OpenForm WhereCondition is like the WHERE clause in a query without the word WHERE.

Upvotes: 2

Fionnuala
Fionnuala

Reputation: 91376

Your first statement looks wrong to me. I suspect you mean "Act", for one thing. Try

If (Me.Type = "Act" _
    And Me.Title <> Null _
    And Me.Section <> Null) _
    Or (Instr("Proposed,Final",Me.Type) >0 
    And Me.Rule <> Null )

I do not believe you cut and pasted your example from your code, it is best to do so.

Upvotes: 0

Related Questions