Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 15th, 2003, 06:38 AM
Authorized User
 
Join Date: Nov 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MrDannyP
Default User Entry

Hello everyone.

Although im new to VB (just got it 2 days ago) I know what I would like.

I have created a database in MS Acess which will hold usernames and passwords, both of which can be edited because I used a data manager so I can now browse through them and edit them as I please.

I cant seem to find any code to tell me how to 'LOOK UP' certain columns of an MS Acess Database.

I have tried the MSDN library but it doesnt supply me with any example, not even a snippet.

Is there any simple code I can use to 'LOOK UP' a column in MS Acess ?

Thankyou

Oh one more thing, is it possible to shut off an application if a user has entered an incorrect password three times ?


Im new.  Please be gentle :)
__________________
Im new.  Please be gentle :)
 
Old November 18th, 2003, 04:30 AM
Authorized User
 
Join Date: Nov 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Danny,

I think you should learn using Recordsets (if you don't know it already). Have you ever tried SQL, ADO and OLEDB ? All these topics should bring you one step closer to interacting with any (Access) database.

However, it's vast and you will need more than one day. :-)

There are lots of good tutorials on the above topics at e.g. Amazon.com

Mike



 
Old December 3rd, 2003, 10:22 PM
Authorized User
 
Join Date: Oct 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Danny,

Here's some sample ADO code to get you going a little to help you out for running some data retrieval in MS-Access.

For example, let's say your database is named UserPwdDB.mdb and your table is named Users.

---------------------------------------------------------------------
' Here's code to open the database and recordset:

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strDataSource As String

strDataSource = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\UserPwdDB.MDB"
cnn.Open strDataSource

' Open the recordset for read-only (random reads):
rst.Open "Users", cnn, adOpenDynamic, adLockReadOnly

' OR Open the recordset for read-only (forward-only starting at top of file
rst.Open "Users", cnn, adOpenForwardOnly, adLockReadOnly

' OR Open the recordset for random updating (allows Find, etc operations)
rst.Open "Users", cnn, adOpenKeyset, adLockPessimistic

' open mode depends on usage of the recordset in your app

---------------------------------------------------------------------
' Here's code to close the recordset and connection objects

rst.Close
cnn.Close

---------------------------------------------------------------------
' Here's code to retrieve the password for a selected user name:

Dim strUserID As String
Dim varPassword As Variant

strUserID = "jdavis"
rst.Find "UserID = '" & strUserID & "'" ' Need single-quote delims for text fields

If rst.EOF Then
   MsgBox "No match was found for the selected userid", vbExclamation, "ERROR"
Else
   varUserPassword = rst.Fields("Password").Value
End If

' I used a variant to store the retrieved password in case there is
' a NULL value in the password field for the selected user

---------------------------------------------------------------------
' Here's code to change the password for an existing user

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strDataSource As String
Dim strUserID As String
Dim strPassword As String

strDataSource = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\UserPwdDB.MDB"
cnn.Open strDataSource

rst.Open "Users", cnn, adOpenKeyset, adLockPessimistic

strUserID = "jdavis"
strPassword = "garfield"

rst.Find "UserID = '" & strUserID & "'" ' Need single-quote delims for text fields

If rst.EOF Then
   MsgBox "No match was found for the selected userid", vbExclamation, "ERROR"
Else
   rst.Fields("Password").Value = strPassword
   rst.Update
End If

rst.Close
cnn.Close

' OR, you can remove the FIND process and indicate that within your recordset open processing like this:

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strDataSource As String
Dim strUserID As String
Dim strPassword As String

strDataSource = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\UserPwdDB.MDB"
cnn.Open strDataSource

strUserID = "jdavis"
rst.Open "SELECT * FROM Users WHERE UserID = '" & strUserID & "'", cnn, adOpenKeyset, adLockPessimistic

If rst.EOF Then
   MsgBox "No match was found for the selected userid", vbExclamation, "ERROR"
Else
   strPassword = "garfield"
   rst.Fields("Password").Value = strPassword
   rst.Update
End If

rst.Close
cnn.Close



' OR, you can do the following using SQL and not using a recordset object at all

Dim cnn As New ADODB.Connection
Dim strDataSource As String
Dim strUserID As String
Dim strPassword As String

strDataSource = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\UserPwdDB.MDB"
cnn.Open strDataSource

strUserID = "jdavis"
strPassword = "garfield"

strSQL = "UPDATE Users " & _
         "SET Password = '" & strPassword "' " & _
         "WHERE UserID = '" & strUserID & "';"
cnn.Execute strSQL

cnn.Close

---------------------------------------------------------------------
' Here's code to add a new user with a password

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strDataSource As String
Dim strUserID As String
Dim strPassword As String

strDataSource = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\UserPwdDB.MDB"
cnn.Open strDataSource

rst.Open "Users", cnn, adOpenKeyset, adLockPessimistic

strUserID = "jdavis"
strPassword = "garfield"

rst.AddNew
rst!UserID = strUserID
rst!Password = strPassword
rst.Update

rst.Close
cnn.Close

' OR, you can do the following using SQL and not using a recordset object at all

Dim cnn As New ADODB.Connection
Dim strDataSource As String
Dim strUserID As String
Dim strPassword As String

strDataSource = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\UserPwdDB.MDB"
cnn.Open strDataSource

strUserID = "jdavis"
strPassword = "garfield"

strSQL & "INSERT INTO Users " & _
         " ( UserID, " & _
         " Password )" & _
         " VALUES " & _
         " ('" & strUserID & "', " & _
         " '" & strPassword & "');"
cnn.Execute strSQL

cnn.Close

---------------------------------------------------------------------
' Here's how to delete an existing row from the table - I only have
' SQL example offhand, though.

Dim cnn As New ADODB.Connection
Dim strDataSource As String
Dim strUserID As String
Dim strPassword As String

strDataSource = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\UserPwdDB.MDB"
cnn.Open strDataSource

strUserID = "jdavis"

strSQL & "DELETE FROM Users " & _
         "WHERE strUserID = '" & strUserID & "';"
cnn.Execute strSQL

cnn.Close

---------------------------------------------------------------------

I hope that this will be something to help you get started. There's actually alot of information out there explaining these and many other types of operations in much greater detail. One of the things that I found very useful was a whitepaper from Microsoft named "Migrating from DAO to ADO" - it shows quite a few examples using DAO, ADO, and even JRO in some cases. You may be able to do a search on the web to locate this.

I kind of put these together quickly and did not have a chance to verify that all code would compile cleanly or execute perfectly, but I will be happy to make any adjustments if necessary.

Good luck!

Warren





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Multi User Order Entry Screen csjenkin1 VB Databases Basics 0 November 30th, 2007 04:29 PM
DOUBLE ENTRY K38AT Access 1 October 23rd, 2007 12:21 PM
Forms or a solution for end user data entry? Scott B SQL Server 2005 0 October 19th, 2007 04:21 AM
Always a New entry scandalous Access 3 January 26th, 2007 04:02 PM
is this user on/offline? boolean db entry? ALEX_GRIM Classic ASP Basics 6 February 5th, 2005 06:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.