Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Posts
    18

    Unanswered: If statement problems

    Hi all, I have a problem (of course!). I have a form with a button (form1). When this button is clicked, I need it to open a form (form2) with two possible scenarios. The first scenario is that no current record exists and form2 opens to a new record. The second scenario is that a record already exists and form2 opens to that particular record. There is a field (field1) on form1 which contains the id field for form2/table etc. So I figure, if field1 is null, then form2 will open to a new record. If field1 is not null, then form2 will open to field1 record.

    Here is the code behind my button. What's wrong?

    Dim lngTypeID As Long

    lngTypeID = Me.TypeID

    If Me.TypeDetailsID <> Null Then

    DoCmd.OpenForm "frmTechnical2", , , "[TypeDetailsID] =" &
    Me.TypeDetailsID

    DoCmd.Close acForm, "frmTechnical"

    Else

    DoCmd.OpenForm "frmTechnical2"

    DoCmd.GoToRecord , "frmTechnical2", acNewRec

    Forms![frmTechnical2]![TypeID] = lngTypeID

    DoCmd.Close acForm, "frmTechnical"

    End If

    This doesn't work. Help any1?
    "For all have sinned, and fallen short of the glory of God"

    - God speaking through Paul

  2. #2
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    What I do is have a macro that opens the related form on this basis

    Open Form2

    [NameNumber]=[Forms]![MainForm]![NameNumber]

    If the match up does not exist your Form2 will open on a blank record. Of course if there is a match up then the apprpriate record is displayed in Form2

    I also include some SetValue actions to insert data from Form1 into Form2 such as ID Number etc. If a related record did open it does not matter that these inserts of ID number etc are done again.

    If Form2 is based on another table then you pick some vital field that would be filled in if the record was to be kept. When Form2 is closed a macro runs on Close and that macro runs a Delete query which will delete all records where that "vital field" is null.

    Mike

  3. #3
    Join Date
    Apr 2004
    Location
    Kampala, Uganda
    Posts
    32
    Its always better to is the IsNull(<statement) when determining whether a value is null or not, e.g.;

    if IsNull(intOrderID) then
    ........

    You shouldn't really use = or <> with null because by definition null is unknown, so null doesn't equal null. IsNull is the only safe way to check for sure.

  4. #4
    Join Date
    Aug 2003
    Posts
    18
    Awesome, "village idiot" - you are no idiot at all, you're a star, thanks
    "For all have sinned, and fallen short of the glory of God"

    - God speaking through Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •