Selasa, 31 Desember 2013

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

 

I would use the method that is easiest to maintain and understand. 

IMO, it's this one:

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 

However, I would probably qualify fraNoteOpts with Me.
Select Case Me.fraNoteOpts 

I'm not sure where the Err.Number and Err.Description would come from.
Also, I typically don't care for GoTo statements.

Duane Hookom MVP
MS Access

________________________________
> From: saigonf7q5@yahoo.com 
>
>
> 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 (2)
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar