I have a program I wrote for my girlfriend and for the most part everything works. But for some reason I am having an issue with the following code.
-
I can only insert 1 record. If I go to insert a second record it won’t do it. I have to close the form and re-open in order to insert another record.
-
Update doesn’t. I am using the exact same code format in other areas and it works fine. I’m at my wits end trying to figure this one out.
' ----> Variables <----
Var dbRow As New DatabaseRow // For adding...
Var rsData As RowSet // For updating...
' ----> Preliminary Code <----
' ----> Main Code <----
If( btnAddUpd.Caption = "Add Bird" ) Then
// This adds the new bird...
dbRow.Column( "bDate" ).StringValue = txtBDate.Text
dbRow.Column( "breed" ).StringValue = cboBreed.Text
'dbRow.Column( "dDate" ).StringValue = txtDead.Text
dbRow.Column( "gender" ).StringValue = txtGender.Text
dbRow.Column( "health" ).StringValue = txtHealth.Text
dbRow.Column( "name" ).StringValue = txtName.Text
dbRow.Column( "notes" ).StringValue = txtNotes.Text
dbRow.Column( "iDate" ).StringValue = txtSicko.Text
dbRow.Column( "status" ).StringValue = "Alive"
dbRow.Column( "legBandLeft" ).StringValue = cboBandLeft.Text
dbRow.Column( "legBandRight" ).StringValue = cboBandRight.Text
// Now to load the record into the database...
Try
dbFinances.AddRow( "tblBirdList", dbRow )
'MessageBox( "Enter success message here." ) // Uncomment when wanted or needed...
Catch e As DatabaseException
MessageBox e.Message
End Try
Else
// Update record...
If (dbFinances.Connect) = True Then
rsData = dbFinances.SelectSQL( "SELECT * FROM tblBirdList WHERE rNum=?", txtRnum.Text )
If( rsData ) = Nil Then
Beep
MsgBox "Record Set Error: " + Str( dbFinances.ErrorCode) + EndOfLine + EndOfLine + dbFinances.ErrorMessage _
+ EndOfLine + EndOfLine + "Error generated from: frmBirds.btnAddUpd."
Exit
Else
Try
rsData.EditRow
rsData.Column( "bDate" ).StringValue = txtBDate.Text
rsData.Column( "breed" ).StringValue = cboBreed.Text
rsData.Column( "dDate" ).StringValue = txtDead.Text
rsData.Column( "gender" ).StringValue = txtGender.Text
rsData.Column( "health" ).StringValue = txtHealth.Text
rsData.Column( "name" ).StringValue = txtName.Text
rsData.Column( "notes" ).StringValue = txtNotes.Text + EndOfLine.UNIX + "Record Updated " + modSystem.mthDate( ) + " at time : " + modSystem.mthTime( ) + "."
rsData.Column( "iDate" ).StringValue = txtSicko.Text
rsData.Column( "status" ).StringValue = txtStatus.Text
dbRow.Column( "legBandLeft" ).StringValue = cboBandLeft.Text
dbRow.Column( "legBandRight" ).StringValue = cboBandRight.Text
rsData.SaveRow
Catch
MessageBox( "Oh crap! UPDATE didn't update..." )
End Try
End If
End If
Me.Caption = "Add Bird"
rsData.Close
// Left leg band...
If( cboBandLeft.Text <> "" ) Then
// Now I have to update the leg band table and "remove" the leg band from the selection process...
rsData = dbFinances.SelectSQL( "SELECT * FROM tblLegBands WHERE bandNumber=?", cboBandLeft.Text )
If( rsData ) = Nil Then
Beep
MsgBox "Record Set Error: " + Str( dbFinances.ErrorCode) + EndOfLine + EndOfLine + dbFinances.ErrorMessage _
+ EndOfLine + EndOfLine + "Error generated from: frmBirds.btnAddUpd."
Exit
Else
Try
rsData.EditRow
rsData.Column( "assigned" ).StringValue = "Y"
rsData.SaveRow
Catch
MessageBox( "Oh crap! UPDATE didn't update..." )
End Try
End If
txtBDate.SetFocus
rsData.Close
End If
// Right leg band...
If( cboBandRight.Text <> "" ) Then
// Now I have to update the leg band table and "remove" the leg band from the selection process...
rsData = dbFinances.SelectSQL( "SELECT * FROM tblLegBands WHERE bandNumber=?", cboBandRight.Text )
If( rsData ) = Nil Then
Beep
MsgBox "Record Set Error: " + Str( dbFinances.ErrorCode) + EndOfLine + EndOfLine + dbFinances.ErrorMessage _
+ EndOfLine + EndOfLine + "Error generated from: frmBirds.btnAddUpd."
Exit
Else
Try
rsData.EditRow
rsData.Column( "assigned" ).StringValue = "Y"
rsData.SaveRow
Catch
MessageBox( "Oh crap! UPDATE didn't update..." )
End Try
End If
txtBDate.SetFocus
rsData.Close
End If
If( txtHealthNotes.Visible )Then
If( txtHealthNotes.Text <> "" ) Then
dbRow.Column( "iDate" ).StringValue = txtSicko.Text
dbRow.Column( "entryDate" ).StringValue = modSystem.mthDate( )
dbRow.Column( "legBand" ).StringValue = cboBandLeft.Text
dbRow.Column( "notes" ).StringValue = txtHealthNotes.Text
dbRow.Column( "status" ).StringValue = txtStatus.Text
dbRow.Column( "health" ).StringValue = txtHealth.Text
// Now to load the record into the database...
Try
dbFinances.AddRow( "tblBirdHealth", dbRow )
'MessageBox( "Enter success message here." ) // Uncomment when wanted or needed...
Catch e As DatabaseException
MessageBox e.Message
End Try
End If
End If
End If
frmBirds.mthClear( )
frmBirds.mthLoadBirdsLstBx( )