passing values over to another form...Bible Database

Local time
Tomorrow, 01:41
Joined
Sep 6, 2024
Messages
33
Hi I've created a cross-reference (see also or related to) pop up form, which will allow users to display any verses that are linked to a specific verse as cross-references. For example, if Verse A mentions or has a thematic link to verse B, this relationship can be displayed and accessed through the cross-reference form. Users can create new associations between the current and other related verses.
however, my Cross-Reference Popup form does not carry over the verse_id from the Verses form.
I've added a button and code to pass the Verse_id from "Verse form" over to fk3_verse_id in "Cross Reference Form" using OpenArgs.ive also added on load event in "Cross-References Form" to enure that the passed OpenArgs value is correctly assigned to the fk3_Verse_id field.
my button opens the Cross_Reference form but does not carry over the Verse_id please see my code below and assist.
below is my code

Code:
'Code for the button that opens the cross-reference form
Private Sub btnOpenCrossReferences_Click()
    On Error GoTo ErrHandler
  
    ' Open the CrossReferences form and pass the Verse_ID as OpenArgs
    DoCmd.OpenForm "frmCrossReferences", , , , , , Me.verse_id
    Exit Sub

ErrHandler:
    MsgBox "Error: " & Err.Description
End Sub

' Code for the Form_Load event of the cross-reference form
Private Sub Form_Load()
    On Error GoTo ErrHandler

    ' Check if OpenArgs has been passed to the form
    If Not IsNull(Me.OpenArgs) Then
        ' Set the fk3_verse_id field to the passed value
        Me!fk3_verse_id = Me.OpenArgs
      
        ' Apply a filter to display only relevant cross-references
        Me.Filter = "fk3_verse_id = " & Me.OpenArgs
        Me.FilterOn = True
    End If
    Exit Sub

ErrHandler:
    MsgBox "Error: " & Err.Description
End Sub
 

Attachments

Last edited by a moderator:
I do not think this is the current front end. I do not see the forms and buttons your describe.
 
If you plan to filter the target form then you can simply pass that in the Where criteria of the OpenForm.
In the target form you can set the FK value as the default setting instead of setting the value of the field (which may not work). Or you can set the value in the before Insert method of the target form.

Code:
 Check if OpenArgs has been passed to the form
If Not IsNull(Me.OpenArgs) Then
  ' Set the fk3_verse_id control default value to the passed value
  Me!fk3_verse_id.defaultvalue = Me.OpenArgs
  'that assumes the control and field name are the same'
  ' Apply a filter to display only relevant cross-references
  'do this in the docmd.open form WHERE criteria'
  ' "FK= = " & me.verseID
End If
Exit Sub
 
If you plan to filter the target form then you can simply pass that in the Where criteria of the OpenForm.
In the target form you can set the FK value as the default setting instead of setting the value of the field (which may not work). Or you can set the value in the before Insert method of the target form.

Code:
 Check if OpenArgs has been passed to the form
If Not IsNull(Me.OpenArgs) Then
  ' Set the fk3_verse_id control default value to the passed value
  Me!fk3_verse_id.defaultvalue = Me.OpenArgs
  'that assumes the control and field name are the same'
  ' Apply a filter to display only relevant cross-references
  'do this in the docmd.open form WHERE criteria'
  ' "FK= = " & me.verseID
End If
Exit Sub
I've attached the correct version, are you able to assist me with this code please
 
Start learning to walk your code with breakpoints and F8.
Then you will spot issues like this.
Plenty of videos on Youtube if you need assistance visually.
 
There is something very wrong with the Cross reference form.
I have only seen this problem with foreign Database that use non latin characters.

I did what @Gasman suggested and found that the on load even is not firing. I did this by simply putting a message box in the event.
I also compiled the code and commented out the bad code.
I then commented out all the code on the cross reference from and tried to see if the open event is firing and the open args is being passed in the on open event. This caused an error eventhough there is no code in the event or on the form.

This is the only code left on the cross reference form.
Code:
Private Sub Form_Open(Cancel As Integer)

End Sub

It throws this error.
activeX.jpg



This is the only time seeing this before and the solution was only use Latin characters.

I do not see anything like that with your db so my only suggestion is to rebuild this form from scratch. That form seems to be corrupt. Do not copy and paste anything when rebuilding that form from any existing form because you can just carry over the corruption.

Maybe someone else can take a look to see if they see what I am seeing, but this form is not working for me.

You can try to decompile the db first.

 
Once you do that add an OnOpen event. You could put a simple message box or leave it empty. See if you get an error.
 

Users who are viewing this thread

Back
Top Bottom