multi user app with Access

shers

Well-known member
Joined
Aug 12, 2007
Messages
86
Programming Experience
1-3
Hi,
I need to create a multi user VB.Net application that connects to Access 2007 and has 2 forms. How do I go about it? Please give me a start up.

Thanks
 
Access forms are able to operate independantly and are directly connected to the database you are building within Access - if designed with the forms. If you what a Windows form and want the controls(dataGridView, textboxes, comboBoxes, etc...) to use the Access database you will need to add the database to your app. 'Add DataSource.' This will build a set of dataset/dataAdapters during the wizard setup. Is this a local database or a remote database for the users to access?
 
The code below will connect to a database, populate a dataset and use a data adapter to check if the values in two textboxes correspond to those values in the database. PLEASE NOTE when writing to the database, e.g. to add a new user, the word 'password' is reserved and will return an error. Overcome this by renaming 'password' entity in actual database to anything else e.g. 'pass'


VB.NET:
Dim con As New OleDb.OleDbConnection ' declare connection object
        Dim ds As New DataSet ' declare dataset
        Dim da As OleDb.OleDbDataAdapter ' declare data adapter
        Dim sql As String ' declare sql string
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.;Data _
        Source = C:\DatabaseName.mdb"  ' assign technology and data source

        con.Open() ' open connection
        sql = "SELECT * FROM DatabaseTableName" ' assign sql statement
        da = New OleDb.OleDbDataAdapter(sql, con) ' create data adapter
        da.Fill(ds, "Dataset Name") ' fill data set and assign name
        con.Close() ' close connection

        ul = ds.Tables("Dataset Name").Rows.Count()
        i = 0

        While i <= ul
            If i < ul Then
                If txtUsername.Text = ds.Tables("UserInfo").Rows(i).Item("Username") And txtPassword.Text = ds.Tables("UserInfo").Rows(i).Item("Pass") Then

' Put Your Success Outcome here.
                    
            ElseIf i = ul Then ' At end of list
                If Me.Visible = True Then ' still visible so user not found
                    MsgBox("ACCESS DENIED")
                Else
                    ' DO NOTHING
                End If
            End If
            i = i + 1
        End While

Good Luck, hope it helped...
 
Last edited:
The code below will connect to a database, populate a dataset and use a data adapter to check if the values in two textboxes correspond to those values in the database.
Yeah, but it's a good example of a bad start. Sorry...

It may be bette rto advise people in future to follow Microsoft's Data Walkthroughs and Video tutorials. Not only do they go to much greater detail and variety than what you wrote here, but they are made by the same people who wrote the language itself:

Visual Basic How Do I Video Series
(see the DW2 link in my sig for data walkthroughs)
 
I do apologise, I did not really explain why and how the code works. I'll be sure to check out those tutorials myself to see the way it is meant to be done. :)

What did you mean by a good example of a bad start, just so I can improve on my style :D
 
What did you mean by a good example of a bad start, just so I can improve on my style :D
People typically operate in the way they first learned and are quite resistant to change. THus if you show a newbie how to access a database using all the common nasty mistakes (putting reams of db code in button handlers, writing SQLs into the code as concatenated strings, digging stuff out of the database manually from the data reader, ignoring advanced type-specific functionality offered by modern constructs such as datasets) they will tend to carry on doing it in this crappy way that should have died with the passing of the 1990s..

Make sure, when teaching someone, that you start them off on the best possible track, rather than giving them something sub-optimal that works and be sure to explain your teachings so that they are put at the "involve me and I'll understand" part of the chinese proverb "Tell me and I'll forget, show me and I may remember, involve me and i'll learn"
 
Back
Top