19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Do While (Not foundFlag) And (Not datCities.Recordset.EOF)<br />

If UCase(datCities.Recordset.Fields(“City”).Value) = strSearchFor Then<br />

foundFlag = True<br />

Else<br />

datCities.Recordset.MoveNext<br />

End If<br />

Loop<br />

If Not foundFlag Then<br />

MsgBox “Unable to locate requested city.”“Not Found”<br />

datCities.Recordset.MoveLast ‘move so that EOF is no longer true<br />

End If<br />

Else<br />

MsgBox “Must enter a city.”, ,“”<br />

End If<br />

End Sub<br />

Private Sub cmdQuit_Click ()<br />

End<br />

End Sub<br />

Private Sub datCities_Validate(Action As Integer, Save As Integer)<br />

‘Prevent a user from adding a city of population under 1 million<br />

Dim strMsg As String<br />

If Val(txtPop1995) < 1 Then<br />

If (Not datCities.Recordset.EOF) And (Not datCities.Recordset.BOF) Then<br />

strMsg = “We only allow cities having a population of ” & _<br />

“at least one million.”<br />

MsgBox strMsg“City too small!”<br />

Action = 0<br />

End If<br />

End If<br />

End Sub<br />

[Run, click the Search button, <strong>and</strong> enter New York.]<br />

COMMENTS<br />

1. App.Path cannot be used when you set the DatabaseName property of a data<br />

control in the Properties window at design time. However, App.Path can be used<br />

in the Form_Load event procedure. For instance, if you add the lines<br />

Private Sub Form_Load()<br />

datCities.DatabaseName = App.Path & “\MEGACTY1.MDB”<br />

End Sub<br />

An Introduction to Databases 329

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!