Selasa, 31 Desember 2013

RE: [MS_AccessPros] IF and SELECT CASE statements coding methods.

 

In my experience, the If Then Else If structure is more susceptible to logical errors than the Select Case structure. That makes If Then more difficult to  more difficult to debug than the case structure. My general preference when dealing with a series of related alternatives is to use the Select Case structure. From an operational point of view, Select Case also executes more efficiently.

 

Glenn

 

From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of saigonf7q5@yahoo.com
Sent: Tuesday, December 31, 2013 3:49 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] IF and SELECT CASE statements coding methods.

 

 

I have an IF statement and a SELECT CASE statement that were coded in 2 different ways as shown. One takes less coding then the other. So far there is no error occurr. Is it always the case, either method is correct.

 

If Me!fraNoteOpts.Value = 1 Then
   sqltext = "Select Distinct id_rssd, [nm_short] From [tbl_A] WHERE [nm_short] Like '" & Chr$(Me![fraButtonFrame]) & "*';"
ElseIf Me!fraNoteOpts.Value = 2 Then
   sqltext = "SELECT Distinct RSSD, BkName FROM tblNotes WHERE BkName Like '" & Chr$(Me![fraButtonFrame]) & "*';"
ElseIf Me!fraNoteOpts.Value = 3 Then
   sqltext = "SELECT Distinct RSSD, BkName FROM tblNotes WHERE BkName Like '" & Chr$(Me![fraButtonFrame]) & "*';"
ElseIf Me!fraNoteOpts.Value = 4 Then
   sqltext = "SELECT Distinct RSSD, BkName FROM tblNotes WHERE BkName Like '" & Chr$(Me![fraButtonFrame]) & "*';"
End If

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

If Me!fraNoteOpts.Value = 1 Then
          sqltext = "Select Distinct id_rssd, [nm_short] From [tbl_A] WHERE [nm_short] Like '" & Chr$(Me![fraButtonFrame]) & "*';"
ElseIf Me!fraNoteOpts.Value = 2 Or Me!fraNoteOpts.Value = 3 Or Me!fraNoteOpts.Value = 4 Then
          sqltext = "SELECT Distinct RSSD, BkName FROM tblNotes WHERE BkName Like '" & Chr$(Me![fraButtonFrame]) & "*';"
End If

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Select Case fraNoteOpts
    Case 1
          sqltext = "select distinct left(nm_short,1)from [tbl_A];"
          fraButtonFrame = Null
    Case 2
          sqltext = "SELECT distinct left(BkName,1)FROM tblNotes;"
          fraButtonFrame = Null
    Case 3
          sqltext = "SELECT distinct left(BkName,1)FROM tblNotes;"
          fraButtonFrame = Null
    Case 4
          sqltext = "SELECT distinct left(BkName,1)FROM tblNotes;"
          fraButtonFrame = Null
    Case Else
          MsgBox Err.Number & vbCrLf & Err.Description
          GoTo ExitProcedure
End Select

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Select Case fraNoteOpts
    Case 1
          sqltext = "select distinct left(nm_short,1)from [tbl_FINAL_A];"
          fraButtonFrame = Null
    Case 2, 3, 4
          sqltext = "SELECT distinct left(BkName,1)FROM tblNotes;"
          fraButtonFrame = Null
    Case Else
          MsgBox Err.Number & vbCrLf & Err.Description
          GoTo ExitProcedure
End Select

 

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar