-->>Hello World of VB 6 Programers...
-->>I've been using a block of Branching statement that worked fine in all the places I've used it...
-->>Now I came to develop this form thats when things started to look bad...
-->>I just check for the availability of a record in a database if exists then 'Error Masage'...
-->>Else i want the values to be store here is the code:
Private Sub btnAdd_Note_Click()
'**************************************************************************'
On Error GoTo errtrap
Call dbConnect
SQL = "SELECT * FROM GPATB WHERE ((GPATB.User_name) = '" & USER_NAME & "');"
RS.Open SQL, Conn, adOpenDynamic
If Not RS.EOF Then
RS.MoveFirst
Do While Not RS.EOF
'*********************************************************************'
'* THIS PART EXECUTE JUST FINE WHEN THERE IS A MATCHING RECORD FOUND *'
'*********************************************************************'
If RS.Fields("User_name") = USER_NAME And RS.Fields("Study_year") = YEAR And RS.Fields("Semister") = SEMISTER Then
MsgBox "G.P.A For Year : " & YEAR & " Semister : " & SEMISTER & " already Exists.", vbOKOnly + vbCritical, "G.P.A Alredy Exists in SPGPAC - File."
End If
RS.MoveNext
Loop
'*********************************************************************'
'* THIS PART DOESNT EXECUTE WHEN THERE IS NO MATCHING RECORD FOUND *'
'*********************************************************************'
Else
Conn.Execute "INSERT INTO GPATB(User_name,Study_year,Semister,GPA,Comments) VALUES ('" & USER_NAME & "','" & YEAR & "','" & SEMISTER & "','" & GPA & "','" & GPA_CLASS & "');"
MsgBox "G.P.A Information of Year " & YEAR & ",Semister " & SEMISTER & " Saved Succesful in SPGPAC - File.", vbOKOnly + vbInformation, "G.P.A Accepted in SPGPAC - File"
End If
Set RS = Nothing
Set Conn = Nothing
Exit Sub
errtrap:
MsgBox Err.Description, vbCritical, "SPGPAC - File System Encountered an Error,You will be Loged out"
'**************************************************************************'
End Sub
-->>But when I change the code Like this:
Private Sub btnAdd_Note_Click()
'**************************************************************************'
On Error GoTo errtrap
Call dbConnect
SQL = "SELECT * FROM GPATB WHERE ((GPATB.User_name) = '" & USER_NAME & "');"
RS.Open SQL, Conn, adOpenDynamic
If Not RS.EOF Then
RS.MoveFirst
Do While Not RS.EOF
'*********************************************************************'
'* THIS PART EXECUTE JUST FINE WHEN THERE IS A MATCHING RECORD FOUND *'
'*********************************************************************'
If RS.Fields("User_name") = USER_NAME And RS.Fields("Study_year") = YEAR And RS.Fields("Semister") = SEMISTER Then
MsgBox "G.P.A For Year : " & YEAR & " Semister : " & SEMISTER & " already Exists.", vbOKOnly + vbCritical, "G.P.A Alredy Exists in SPGPAC - File."
Set RS = Nothing
Exit Sub
'*******************************************************************************'
'* THIS PART EXECUTE JUST FINE AS WELL WHEN THERE IS NO A MATCHING RECORD FOUND *'
'*******************************************************************************'
Else
Conn.Execute "INSERT INTO GPATB(User_name,Study_year,Semister,GPA,Comments) VALUES ('" & USER_NAME & "','" & YEAR & "','" & SEMISTER & "','" & GPA & "','" & GPA_CLASS & "');"
MsgBox "G.P.A Information of Year " & YEAR & ",Semister " & SEMISTER & " Saved Succesful in SPGPAC - File.", vbOKOnly + vbInformation, "G.P.A Accepted in SPGPAC - File"
End If
RS.MoveNext
Loop
End If
Set RS = Nothing
Set Conn = Nothing
Exit Sub
errtrap:
MsgBox Err.Description, vbCritical, "SPGPAC - File System Encountered an Error,You will be Loged out"
'**************************************************************************'
End Sub
-->>1.So I was wondering what is wrong for the two codes that it works fine in other forms but only here?
-->>2.Is there any demages that can apper form either of the two code blocks?
-->>3.Which one seems to be the right way of Branching?
-->>Thanks...