Solved bible database (1 Viewer)

Local time
Today, 18:03
Joined
Sep 6, 2024
Messages
34
Hi I'm developing my first access database, which is a bible database. So on my Books Form, I have a combobox "Book Name" from here I get to choose a book, thereafter I will click on a button "Open Verses" which will open a form "Verses" which is a split form, tabular ontop and datasheet at the bottom. this "Verses Form" should display the chapter number, verse number and text from the book I selected in the combobox in my "Books Form", however it only displays Genesis properties no matter which book I select in my combobox. below I've provided my buttons onclick event procedure. I have also attached 3 images of my 2 forms for visual clarity.

what I would like assistance on is how do I get my "Verses Form" to display results based on the Book I selected in the combobox every time.

Private Sub btnOpenBooksVerses_Click()
' Ensure the combo box is not empty
If Not IsNull(Me.comboSelectBook) Then
' Use Nz() to avoid errors with null values and pass the second column (book name)
Dim strBookName As String
strBookName = Nz(Me.comboSelectBook.Column(1), "")

' Open the Verses form and pass the selected book name in OpenArgs
If strBookName <> "" Then
DoCmd.OpenForm "frmVerses", , , , , , strBookName
Else
MsgBox "No book name found."
End If
Else
MsgBox "Please select a book."
End If
End Sub
 

Attachments

  • Screenshot (9).png
    Screenshot (9).png
    179.8 KB · Views: 38
  • Screenshot (8).png
    Screenshot (8).png
    166.3 KB · Views: 36
  • Screenshot (7).png
    Screenshot (7).png
    174.9 KB · Views: 36
The WhereCondition argument of the OpenForm method is only three commas away, which is what I would suggest using here. As it is, your code seems to be using the OpenArgs argument, but you haven't shown us how you're using it in the Open event of the Verses form.
 
yes sure, at the logon page username = waldin, password = userone
please keep in mind my database is still under construction 🙈

thanks for your speedy response Bob
 

Attachments

The WhereCondition argument of the OpenForm method is only three commas away, which is what I would suggest using here. As it is, your code seems to be using the OpenArgs argument, but you haven't shown us how you're using it in the Open event of the Verses form.
hi thank you, please see below

Private Sub Form_Load()
' Check if OpenArgs contains a value
If Not IsNull(Me.OpenArgs) Then
' Display the value from OpenArgs in the textbox
Me.SelectedBook.Value = Me.OpenArgs
End If
End Sub

Private Sub SelectedBook_Click()
Private Sub btnOpenVerses_Click()
' Ensure the combo box is not empty
If Not IsNull(Me.cmbBookName) Then
' Use Nz() to avoid errors with null values and pass the second column (book name)
Dim strBookName As String
strBookName = Nz(Me.cmbBookName.Column(1), "")

' Open the Verses form and pass the selected book name in OpenArgs
If strBookName <> "" Then
DoCmd.OpenForm "VersesForm", , , , , , strBookName
Else
MsgBox "No book name found."
End If
Else
MsgBox "Please select a book."
End If
End Sub
End Sub
 
yes sure, at the logon page username = waldin, password = userone
please keep in mind my database is still under construction 🙈

thanks for your speedy response Bob
I thought you might have spoilt us and included the tables
 
You need
OPTION EXPLICIT
at the top of every module then try to compile your code

Come on now. You ever seen code like this? Not going to work.
Code:
Private Sub SelectedBook_Click()
Private Sub btnOpenVerses_Click()

    ' Ensure the combo box is not empty
    If Not IsNull(Me.cmbBookName) Then
        ' Use Nz() to avoid errors with null values and pass the second column (book name)
        Dim strBookName As String
        strBookName = Nz(Me.cmbBookName.Column(1), "")

        ' Open the Verses form and pass the selected book name in OpenArgs
        If strBookName <> "" Then
            DoCmd.OpenForm "VersesForm", , , , , , strBookName
        Else
            MsgBox "No book name found."
        End If
    Else
        MsgBox "Please select a book."
    End If

End Sub
End Sub
 
Private Sub Form_Load()
' Check if OpenArgs contains a value
If Not IsNull(Me.OpenArgs) Then
' Display the value from OpenArgs in the textbox
Me.SelectedBook.Value = Me.OpenArgs
End If
End Sub
As I said, using the WhereCondition is probably simpler, but I think the above should probably be more something like:
Code:
If Not IsNull(Me.OpenArgs) Then
    Me.Filter = "BookID=" & Me.OpenArgs
    Me.FilterOn = True
End If
However, please note that the OpenArgs value is only assigned, I think, when the form first opens. So, if you don't close the form first and select a different book name from the main form, the OpenForm method won't update the OpenArgs vaue.
 
Last edited:
Again you have to compile the code because it does not make sense. You reference controls that do not exist as well as having procedures inside procedures. No such thing as "cmbBookName"
Code:
Private Sub SelectedBook_Click()
    ' Ensure the combo box is not empty
    If Not IsNull(Me.cmbBookName) Then
        ' Use Nz() to avoid errors with null values and pass the second column (book name)
        Dim strBookName As String
        strBookName = Nz(Me.cmbBookName.Column(1), "")

        ' Open the Verses form and pass the selected book name in OpenArgs
        If strBookName <> "" Then
            DoCmd.OpenForm "VersesForm", , , , , , strBookName
        Else
            MsgBox "No book name found."
        End If
    Else
        MsgBox "Please select a book."
    End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom