-
Dim db As Database
-
Dim rs As Recordset
-
Dim WS As Workspace
-
Dim Max As Long
-
-
-
Private Sub Form_Load()
-
Set WS = DBEngine.Workspaces(0)
-
DbFile = (App.Path & "\Database\AddressBook.mdb")
-
PwdString = "swordfish"
-
Set db = DBEngine.OpenDatabase(DbFile, False, False, ";PWD=" & PwdString)
-
Set rs = db.OpenRecordset("Addresses", dbOpenTable)
-
Max = rs.RecordCount
-
lblTotalContacts.Caption = Max
-
If rs.RecordCount = 0 Then
-
Exit Sub
-
Else
-
rs.MoveFirst
-
-
List1.Clear
-
-
For i = 1 To Max
-
List1.AddItem rs!FullName
-
rs.MoveNext
-
Next i
-
List1.ListIndex = 0
-
End If
-
ButtonsEnabled
-
End Sub
-
-
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
-
ButtonsEnabled
-
End Sub
-
-
Private Sub Form_Unload(Cancel As Integer)
-
End
-
End Sub
-
-
Private Sub List1_Click()
-
Set WS = DBEngine.Workspaces(0)
-
DbFile = (App.Path & "\Database\AddressBook.mdb")
-
PwdString = "swordfish"
-
Set db = DBEngine.OpenDatabase(DbFile, False, False, ";PWD=" & PwdString)
-
Set rs = db.OpenRecordset("Select * from Addresses where FullName = '" & Trim(List1.List(List1.ListIndex)) & "'")
-
On Error GoTo ErrorHandler
-
lblName.Caption = rs("FullName")
-
lblNationality.Caption = rs("Nationality")
-
lblCountry.Caption = rs("Country")
-
lblBirthday.Caption = rs("Birthday")
-
lblCountry.Caption = rs("Country")
-
lblCity.Caption = rs("City")
-
lblAddress.Caption = rs("Address")
-
lblPhoneNumber.Caption = rs("PhoneNumber")
-
lblMobile.Caption = rs("Mobile")
-
lblFax.Caption = rs("Fax")
-
lblEMAIL.Caption = rs("E-Mail")
-
lblWebSite.Caption = rs("WebSite")
-
lblCompany.Caption = rs("Company")
-
Text1.Text = rs("LittleComment")
-
ErrorHandler:
-
Resume Next
-
End Sub
1 2801 -
'declare variables to be used and in this case these variables represent DAO (Data Access Object) objects although so you can understand more the order has been changed by me to more represent the heirarchy of the objects
-
Dim WS As Workspace
-
Dim db As Database
-
Dim rs As Recordset
-
-
Dim Max As Long
-
-
-
'this even is called after initialize
-
Private Sub Form_Load()
-
-
'create the workspace via the dbengine (jet) object
-
Set WS = DBEngine.Workspaces(0)
-
-
'this example you have shown is an example of bad programming practice as none of these variables are declared. To remedy this place Option Explicit at top of code window prior to any declarations
-
DbFile = (App.Path & "\Database\AddressBook.mdb")
-
PwdString = "swordfish"
-
-
'open the database
-
Set db = DBEngine.OpenDatabase(DbFile, False, False, ";PWD=" & PwdString)
-
-
'open a recordset, namely the addresses table
-
Set rs = db.OpenRecordset("Addresses", dbOpenTable)
-
-
'retrieve the number of records and display
-
Max = rs.RecordCount
-
lblTotalContacts.Caption = Max
-
-
'check to see if there are any records
-
If rs.RecordCount = 0 Then
-
-
'no records so exit this sub
-
Exit Sub
-
Else
-
-
'have records so position the recordset cursor to the first record
-
rs.MoveFirst
-
-
'clear list1
-
List1.Clear
-
-
'now run through rs and add the information to list1
-
For i = 1 To Max
-
List1.AddItem rs!FullName
-
rs.MoveNext
-
Next i
-
List1.ListIndex = 0
-
End If
-
-
'call a sub that enables/disables buttons depending upon...?
-
ButtonsEnabled
-
End Sub
-
-
'this event is called when the mouse moves over the form
-
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
-
'call sub...
-
ButtonsEnabled
-
End Sub
-
-
Private Sub Form_Unload(Cancel As Integer)
-
-
'another example of bad programming practice with vb6 as this does not allow you to properly close your object that you have opened and may lead to memory leaks and system instability
-
End
-
End Sub
-
-
'when user clicks on an item in list1 this event is called
-
Private Sub List1_Click()
-
-
'the following lines are not needed as the workspace is already created and the database is already opened...
-
'Set WS = DBEngine.Workspaces(0)
-
'DbFile = (App.Path & "\Database\AddressBook.mdb")
-
'PwdString = "swordfish"
-
'Set db = DBEngine.OpenDatabase(DbFile, False, False, ";PWD=" & PwdString)
-
-
'open a recordset based upon user selection
-
Set rs = db.OpenRecordset("Select * from Addresses where FullName = '" & Trim(List1.List(List1.ListIndex)) & "'")
-
-
'tell compiler that we will attempt to handle any errors after this label below
-
On Error GoTo ErrorHandler
-
-
'another example of bad programming practice as these should be rs.fields("fieldname") for complete readability and for easier maintence by the noobie
-
lblName.Caption = rs("FullName")
-
lblNationality.Caption = rs("Nationality")
-
lblCountry.Caption = rs("Country")
-
lblBirthday.Caption = rs("Birthday")
-
lblCountry.Caption = rs("Country")
-
lblCity.Caption = rs("City")
-
lblAddress.Caption = rs("Address")
-
lblPhoneNumber.Caption = rs("PhoneNumber")
-
lblMobile.Caption = rs("Mobile")
-
lblFax.Caption = rs("Fax")
-
lblEMAIL.Caption = rs("E-Mail")
-
lblWebSite.Caption = rs("WebSite")
-
lblCompany.Caption = rs("Company")
-
Text1.Text = rs("LittleComment")
-
-
'label for the error handler. Also, missing the exit sub statement before this line
-
ErrorHandler:
-
-
'basically we are telling the compiler that we are trying to ignore any errors and to go to the next line and if that is so then we could have used the On Error Resume Next statement instead of telling the system that we will try to handle the error
-
Resume Next
-
End Sub
Hope that helps
Good Luck
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Colin MacDougall |
last post by:
Hi,
I am just starting to learn Visual Basic 6 and
was wondering if just going straight on to
VB.NET would be a better bet. Is VB.NET just
a newer version of Visual Basic 6 or does it
differ radically? My main reason for programming
in VB is to build a data logger that reads,
processes and stores bytes from an external device
through the serial port and then exports it to an
|
by: Will |
last post by:
I just discovered Python and looked briefly at one of the tutorials
for beginners...
It looks a lot like the old Command line Basic... I'm sure it does
much more but...
1 - Can you create windows, buttons, user input fields, etc as you
can with Visual Basic?
2 - Can you call Windows Procedures or what ever they call them
|
by: hooi |
last post by:
I'm new to Visual Studio.NET and Visual Basic.NET. While trying to run the
sample application, it shows an error message as shown below. I have an SQL
Server containing the sample database Northwind used in this application.
Authentication mode set in Web.config is Windows; Mixed mode in the SQL
Server. Any idea how I can resolve this problem? Thanks...
Server Error in '/HowToBuildAWebDataEntryApp' Application....
|
by: developer |
last post by:
Does anyone know what is the way IE treats span tags(<span>) and table
tags(<tr>, <td>)? Should the <span> tag be encolsed in tds and trs if
it placed with other elements that are in a table? Can the span tag
itself contain table tags within it?
I have some scripting code and when I wrap the span in table elements
it does not find the html within the span. Here is an example....
<tr><td colspan="4" align="left"><span...
|
by: typingcat |
last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so
on. I've tried many PHP IDEs today, but almost non of them supported
Unicode (UTF-8) file.
I've found that the only Unicode support IDEs are DreamWeaver 8 and
Zend PHP Studio.
DreamWeaver provides full support for Unicode. However, DreamWeaver is
a web editor rather than a PHP IDE. It only supports basic IntelliSense
(or code completion) and doesn't have anything...
| |
by: Sathyaish |
last post by:
I wanted to practice some Linked List stuff, so I set out to create a
linked list. The plan was to create the following:
(1) A linked list class in Visual Basic
(2) A non-class based linked list using functions in C
(3) A linked list class in C++
I started with Visual Basic and I wrote an IList interface that I
wanted my list to implement. When I had started, somehow I thought
this time, I'd first use a collection as the ingredient,...
|
by: Mountain Bikn' Guy |
last post by:
What is the current preferred way to save user preferences in dotnet? Is the
registry the right place to do this? Can anyone recommend a good article (or
book) for this topic? Thanks.
|
by: Mike Hofer |
last post by:
While I'd toyed with C, C++, and Java over the last 20 years or so, my
principal language has been BASIC, QBASIC, then Visual Basic, and
finally Visual Basic .NET. But lately, I've been using C# and I
absolutely *love* it. It makes me think more about what I'm doing it
before I just spew code into the editor. I'm writing better code than
ever.
The only thing so far that I don't like about it is the switch
construct. I can't do this:
|
by: kevin |
last post by:
I have a form and in the form I have a sub that uses a class I instantiate
using
visual basic code: Public oCP As New Rs232 'instantiate the comm port
I need to share this sub with another form so to declare the sub I use
visual basic code: Public Shared Function IsPortAvailable(ByVal ComPort
As Integer) As Boolean
|
by: Dr. Zharkov |
last post by:
Hello. To see the graphics of technology DirectX 9.0 SDK Update - June 2005
in project Visual Basic, WindowsApplication1 from Visual Studio 2005 Beta 1,
in file My Project, MyApplication.vb in a method:
<Global.System.Diagnostics.DebuggerStepThrough()> _
Protected Overrides Sub OnCreateMainForm()
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |