Select Case - What am I doing wrong? 
Author Message
 Select Case - What am I doing wrong?

1.  Where do you call this code on each form?
2.  Comment out a whole bunch and add some message boxes, such that your
case is like this

Select Case Macek
    Case "Main Information"
        strMsg =  "Case Main information.  CaseName is "
        strMsg = strMsg & Forms![Main Information]![CaseName]
        strMsg = strMsg & vbcrlf & " Nz is " & Nz(Forms![Main
Information]![CaseName])
        msgbox strMsg
    Case "Client Information"
        strMsg =  "Case Client information.  LastName is "
        strMsg = strMsg & Forms![Client Information]![LastName]
        strMsg = strMsg & vbcrlf & " Nz is " & Nz(Forms![Client
Information]![LastName])
        msgbox strMsg
    Case "Cases That Match Client ID"
        strMsg =  "Case Cases that Match.  ClientType is "
        strMsg = strMsg & Forms![Cases That Match Client ID]![ClientType]
        strMsg = strMsg & vbcrlf & " Nz is " & Nz(Forms![Cases That Match
Client ID]![ClientType])
        msgbox strMsg
End Select

See what's working and what's not - report back with details.  Notice you
use Nz() <> 0 in case of Cases That Match - that doesn't sound like what you
are looking for.

Let us know what these messages return.

Keri



    This is a revised copy of an earlier post - still looking for the
answer.  Now, however, the plot has thickened!
    I have three different forms which may open with no records (resulting
in a completely blank form).  For the first: "Main Information", the
function below catches the error, closes the form, then opens a custom error
form displaying alternatives.  Calling the same function to check the other
two forms: "Client Information" and "Cases That Match Client ID" does not
work.  Instead, the blank form simply shows up instead.  I expect the
problem is in the way I am using Select Case, but I can't seem to nail it
down.  Any ideas?

    It was suggested that I replace lines like
      If Nz(Forms![Main Information]![CaseName]) = 0 Then
    with
      If Nz(Forms![Main Information]![CaseName],"") = "" Then

    but this has not had any affect.  I also tried moving the order of the
Cases around, but the function works (fails) the same.  I know that they are
being read - I put in some simple MsgBoxes to verify this.

    In addition, I found out something interesting: the Main Information
form does NOT have any controls called CaseName.  The control that used to
be called that is now called Text316 (not sure when it got changed and I'm
not going to mess with it if it is working).  I checked the Object drop-down
list and cannot find one anywhere.  How can the function work properly if
this control is not even there to check???  Again, this is the Case that
works properly!  The controls referenced by the other Cases DO exist, but
they just get ignored.

    Thanks a ton in advance,
    John Breen

    Function CurForm()
    On Error GoTo Exit_CurForm

    Dim frmCurrentForm As Form, I As Integer, Macek As String

    Set frmCurrentForm = Screen.ActiveForm
    Macek = frmCurrentForm.Name

    Select Case Macek
        Case "Main Information"
            Forms![Main Information]![IRID Subform].Visible = True
            Forms![Main Information]![LFID Subform].Visible = True
            Forms![Main Information]![Main Info - Holder subform].Visible =
True
            If Nz(Forms![Main Information]![CaseName]) = 0 Then
               Forms![Main Information].Visible = False
               DoCmd.Close acForm, "Main Information"
               DoCmd.OpenForm "Alert - Main Info - No Records Found"
               Forms![Alert - Main Info - No Records
Found]![NewSearch2].Visible = True
            Else
            End If
        Case "Client Information"
            If Nz(Forms![Client Information]![LastName]) = 0 Then
               Forms![Client Information].Visible = False
               DoCmd.Close acForm, "Client Information"
               DoCmd.OpenForm "Alert - Main Info - No Records Found"
               Forms![Alert - Main Info - No Records
Found]![NewSearchClient].Visible = True
            Else
            End If
        Case "Cases That Match Client ID"
            If Nz(Forms![Cases That Match Client ID]![ClientType]) <> 0 Then
               Forms![Cases That Match Client ID].Visible = False
               DoCmd.Close acForm, "Cases That Match Client ID"
               DoCmd.OpenForm "Alert - Main Info - No Records Found"
            Else
            End If
    End Select

    Exit_CurForm:
        Exit Function

    End Function



Fri, 01 Feb 2002 03:00:00 GMT  
 Select Case - What am I doing wrong?
Basically John you're using a very strange way of establishing whether there
are any records behind your form.

Why not try actually looking at the records rather then a text box on the
form

If you try putting this function in a global module:-

Function noRecords(currentForm As Form) As Boolean
On Error GoTo noRecords_err
Dim lrst1 As Recordset
Dim recordCount As Integer

Set lrst1 = currentForm.RecordsetClone
lrst1.MoveLast
lrst1.MoveFirst
recordCount = lrst1.recordCount

If recordCount = 0 Then
    noRecords = True
Else
    noRecords = False
End If

noRecords_exit:
Exit Function

noRecords_err:
If Err.number = 3021 Then
    noRecords = True
    Resume noRecords_exit
Else
    MsgBox Err.number & " " & Err.Description
    Resume noRecords_exit
End If

End Function

then on the Open event of the forms concerned do something like

If noRecords(Me) then
    msgbox "No records on this form"
    DoCmd.close
    'Open alternative form
    'Whatever you want to do
End if

HTH



Sat, 02 Feb 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Recordset: What am I doing wrong?

2. What am I doing wrong??

3. What am I doing wrong?

4. Help with syntax. What am I doing wrong

5. What am I doing wrong?

6. What am I doing wrong?

7. What am I doing wrong?

8. Please tell me what I am doing wrong - DAO parameter Append Query :(

9. What am I doing wrong? -MultiSelect List box

10. What am I doing wrong (easy).

11. OLE problem, or what am I doing wrong?

12. What am I doing wrong?

 

 
Powered by phpBB® Forum Software