This is my login form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=C:/Users/Space Era/Documents/User.mdb")
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Users WHERE userid = '" & TextBox2.Text & "' AND password = '" & TextBox1.Text & "' ", con)
        con.Open()
        Try
            Dim sdr As OleDbDataReader = cmd.ExecuteReader()
            ' If the record can be queried, Pass verification and open another form.  
            If (sdr.Read() = True) Then

                Form4.Show()
                Me.Hide()
            Else


                MessageBox.Show("Invalid username or password!")
            End If
        Catch ex As Exception

            MsgBox(ex.Message, MsgBoxStyle.Critical, "Oledb Error")

        End Try
    End Sub

    Private Sub Cancel_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

Now i want to add a logout linklabel to the main form i.e. form4 ,how do i code it to logout the user and show the login form

Set the "Shutdown mode:" in fileMenu/Project/your app's Properties, Application tab To "When last form closes".

I want to add a logout linklabel so that when i click on it ,,the login form shows up with empty username and password fields

This is the LinkLabel.Form and Form1 is your login.Form.

Public Class Form2

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Me.Hide()
        With Form1
            .TextBox1.Clear() : .TextBox2.Clear() '// un/pw TextBoxes.
            .ShowDialog()
        End With
        Me.Close()
    End Sub
End Class

that was helpful,,thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.