Logins

[VBA Access] 1st interactive Form

!To see the pics in the full size click  on them ritht botton mouse and select option: open a graphic in a new tab

First step we need to take is to import tables from SQL. We have 2 options:

  • we can export database from SQL into Access
  • or import database directly in Ms Access by clicking on Data –> Importing [—>More] –> ODBC databases

Making step by step we will be asking about objects we would like to import, my sugesstion is to chose 3 of them, only tables:

  1. dbo_ADDRESSES,
  2. dbo_LOGINS,
  3. dbo_PRODUCTS

Music4Ever_SOP 1

When database objects were succesfully imported, we need to check that we have any values inside tables we need

Music4Ever_SOP 2

and create a simple query ( name: qry_Logins), that will be our base to create login window – Log In Form.

Music4Ever_SOP 3.jpg

Import done, query done, time to create form. Go to section Forms –> Form Project and choose the folowing objects:

Music4Ever_SOP 4.jpg

It is important to name each of the object properly, cause this will be needed to make a VBA Code with references to them (name of the bottons we can change by open property sheey in section Creating –> Forms (tab: other after clicking on the botton).

If we we get final lay out for our form we can start to write pur first VBA Code in Access.

To write our code inside the Form we need to choose bottom named bltLogin (login) and event tab in property sheet section, next: event procedure —> macro bulider.

Write a code silimiar to this one:

Music4Ever_SOP 5.jpg

Private Sub btLogin_Click()
Dim rs As Recordset

Set rs = CurrentDb.OpenRecordset(“qry_LOGINS”, dbOpenSnapshot, dbReadOnly)

rs.FindFirst “Login = ‘” & Me.tLogin & “‘”

If rs.NoMatch = True Then
Me.xWrongUser.Visible = True
Me.tLogin.SetFocus
Exit Sub
End If
Me.xWrongUser.Visible = False
If rs!Password <> Me.tPassword Then
Me.xWrongPass.Visible = True
Me.tPassword.SetFocus
Exit Sub
End If

Me.xWrongPass.Visible = False
‘opening next form after correct login and password
DoCmd.OpenForm “formAdresses”
‘closing current opened form
DoCmd.Close acForm, Me.Name
End Sub 

Try to make in on your own, I undrelined name of the objects inside to make it easier to find.