Navigation on Microsoft Access form using macros

Navigation on Microsoft Access Forms using macros

This article is on how to navigate on form using macros. For navigation on form we have current form, previous form and next form. We are using macros for navigation .When we execute the macro automatically the navigation is working followed by the procedure.

Firstly we have to create the table as shown in Fig 1.1.

Microsoft Word mail merge from Microsoft Access Database Fig-1.1

Fig-1.1

Then we have to create the related form as shown in Fig 1.2. And also we have to make three copies of that form for current, next and previous form navigation. Also we have write code for Button events.

Microsoft Word mail merge from Microsoft Access Database Fig-1.2

Fig-1.2

Then we have created the macro as shown in Fig 1.3. And we have the set the navigation procedure.

We have to set the window mode argument Hidden to all and one for Normal, So that only one form is activated on one time.

Microsoft Word mail merge from Microsoft Access Database Fig-1.3

Fig-1.3

Now run the Macro after the coding part and click on next and forward button, it will make you Navigate through different forms as shown in Fig 1.4.

Microsoft Word mail merge from Microsoft Access Database Fig-1.4

Fig-1.4

VBA code for form Navigation:

Option Compare Database
Private Sub Forward_Click()
Back_forward "F", Me.Name
End Sub

Private Sub Back_Click()
Back_forward "B", Me.Name
End Sub

Public Function Back_forward(ByVal strStatus As String, ByVal strForm As String)
Dim count As Integer
Dim icnt As Integer
count = Forms.count - 1
On Error GoTo Back_forward_Err
count = Forms.count - 1
For icnt = 0 To count
Select Case strStatus
Case "B"
If Forms(icnt).Name = strForm And icnt - 1 >= 0 Then
DoCmd.SelectObject acForm, Forms(icnt - 1).Name, False
Forms(strForm).Visible = False
Forms(icnt - 1).Visible = True
Exit For
End If
Case "F" If Forms(icnt).Name = strForm And count > icnt Then
DoCmd.SelectObject acForm, Forms(icnt + 1).Name, False
Forms(strForm).Visible = False
Forms(icnt + 1).Visible = True
Exit For
End If
End Select
Next
Back_forward_Exit:
Exit Function
Back_forward_Err:
MsgBox Err & ":" & Err.Description, , "Back_forward()"
Resume Back_forward_Exit
End Function


DISCLAIMER

It is advised that the information provided in the article should not be used for any kind formal or production programming purposes as content of the article may not be complete or well tested. Access Guru will not be responsible for any kind of damage (monetary, time, personal or any other type) which may take place because of the usage of the content in the article.