Solved Problem with continuous form (1 Viewer)

disgracept

Member
Local time
Today, 22:10
Joined
Jan 27, 2020
Messages
30
Hi all!

I'm having a problem that i really can't figure out why it happens (my bad of course...)

I'm making a database to manage properties and there i have a form to search the properties, like this:

1.png


The list of properties is a continuous subform that has the address, the view button and some hidden textboxes with the elements of the address i use to compose the full address. One of these textboxes is the property ID field. The recordsource of this subform is a query.

The view button has this code:
Code:
Private Sub img_VerImovel_Click()

    DoCmd.OpenForm "frm_VerImovel", acNormal, , "Imovel_ID = " & Me.txt_ImovelID
   
End Sub

But when i click in the buttons the target form opens always in the first record and not in the current one for that particular button...
I've tried to use the full path to the subform, instead of Me.(...), like this:
Code:
Private Sub img_VerImovel_Click()

    DoCmd.OpenForm "frm_VerImovel", acNormal, , "Imovel_ID = " & [Forms]![frm_pesquisaImoveis]![frm_ResultadosSimples].[Form].txt_ImovelID
   
End Sub

But still doesn't work, gives the same result!

What am i doing wrong? How do i access in buttons code the current record info?

Thanks for your help!
Carlos
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 14:10
Joined
Oct 29, 2018
Messages
21,546
Try unhiding the ID textbox to see what's in it.
 

disgracept

Member
Local time
Today, 22:10
Joined
Jan 27, 2020
Messages
30
Hi theDBguy! Thanks for the feedback.

It's all ok... The IDs are there...

2.png


But it keeps opening in the ID=2
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:10
Joined
Sep 21, 2011
Messages
14,465
Put the criteria into a string variable.
Debug.print that until you get it correct.
Then use that variable in the openform command.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:10
Joined
Feb 19, 2002
Messages
43,486
Do you have code in the second form that is overriding the where clause you are sending?
 

disgracept

Member
Local time
Today, 22:10
Joined
Jan 27, 2020
Messages
30
Do you have code in the second form that is overriding the where clause you are sending?
No... The form is clean of any code...

The problem isn't with the form that i open. The problem is that the button isnt't getting the current record ID. It gets the first ID that the recordsource gives (the 2) and passes this value always instead of the correct one for that particular record.

But i don't understand why because the full address is made based on the current record other values. The value for this textbox is set to:
Code:
=makeAddress([Forms]![frm_pesquisaImoveis]![frm_ResultadosSimples].[Form];False)

And the code for this function is:
Code:
Public Function makeAddress(currForm As Form, multiLine As Boolean)
    Dim Morada As String
    Dim separator As String
   
    If multiLine Then
        separator = vbCrLf
    Else
        separator = ", "
    End If
    Morada = ""

    If currForm!txt_NomeVia <> "" Then
        Morada = currForm!txt_TipoVia & " " & currForm!txt_NomeVia
        If currForm!txt_Num <> "" Then
            Morada = Morada & ", " & currForm!txt_TipoNum & " " & currForm!txt_Num
        End If
        If currForm!txt_Andar <> "" Then
            Morada = Morada & ", " & currForm!txt_Andar
            If currForm!txt_Lado <> "" Then
                Morada = Morada & " " & currForm!txt_Lado
            End If
        End If
        If currForm!txt_Cod2 <> "" Then
            Morada = Morada & separator & currForm!txt_Lugar & separator & currForm!txt_Cod1 & "-"
            Morada = Morada & Format(currForm!txt_Cod2, "000") & " " & currForm!txt_Localidade
        End If
    End If
    makeAddress = Morada
End Function

And it works like a charm... So why doesn't it get the correct ID if it gets the other address elements right??? 😢
 
Last edited:

cheekybuddha

AWF VIP
Local time
Today, 22:10
Joined
Jul 21, 2014
Messages
2,328
Try it with just:
Code:
Private Sub img_VerImovel_Click()

    DoCmd.OpenForm "frm_VerImovel", acNormal, , "Imovel_ID = " & [txt_ImovelID]
  
End Sub
 

disgracept

Member
Local time
Today, 22:10
Joined
Jan 27, 2020
Messages
30
Try it with just:
Code:
Private Sub img_VerImovel_Click()

    DoCmd.OpenForm "frm_VerImovel", acNormal, , "Imovel_ID = " & [txt_ImovelID]
 
End Sub
Nope... Still the same...
It's driving me crazy! 🤧
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:10
Joined
Feb 19, 2002
Messages
43,486
You don't use the full address when you are IN the form. You use "Me.controlname"

@Gasman asked you to put the value in a variable so you can print it and see what is being sent to the new form.
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:10
Joined
Sep 21, 2011
Messages
14,465
I can replicate this?
Even if I use a double click on a control to open the form?
1715359234688.png

1715359269584.png
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:10
Joined
Oct 29, 2018
Messages
21,546
Nope... Still the same...
It's driving me crazy! 🤧
Try changing your button code to a simple:

MsgBox Me.[NameOfIDfield]

And verify that you're getting the correct values as you click on different buttons.
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:10
Joined
Sep 21, 2011
Messages
14,465
You are missing a comma. :( so using the Filter option
Code:
Private Sub Command26_Click()
Dim lngID As Long, strCriteria As String
lngID = Me.DailyID
Debug.Print "ID is "; lngID
strCriteria = "DailyID = " & lngID
Debug.Print strCriteria
'DoCmd.OpenForm "frmDaily", , , "DailyID = " & lngID
DoCmd.OpenForm "frmDaily", , , strCriteria
End Sub

Edit: No, you are using an extra parameter, which I am not. :(
 

cheekybuddha

AWF VIP
Local time
Today, 22:10
Joined
Jul 21, 2014
Messages
2,328
Yes, perhaps image control can't receive focus, so it isn't changing the current record
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:10
Joined
Sep 21, 2011
Messages
14,465
Are you sure? The second argument (View:=acNormal) is present, and Where comes two after that.
Yes, I missed that and edited my post, but I was getting the same behaviour initially, due to that. :(

Now it is working for me?
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:10
Joined
Sep 21, 2011
Messages
14,465
Create a new form quickly and try the code again.
 

cheekybuddha

AWF VIP
Local time
Today, 22:10
Joined
Jul 21, 2014
Messages
2,328
It is the image.

I placed an image and a button on a continuous form, each with a click event to MsgBox the record ID.

Clicking image only picks up the ID of the first record, whichever record is clicked.

Clicking Button shows correct ID as expected.
 

disgracept

Member
Local time
Today, 22:10
Joined
Jan 27, 2020
Messages
30
You don't use the full address when you are IN the form. You use "Me.controlname"

@Gasman asked you to put the value in a variable so you can print it and see what is being sent to the new form.
I did it… always passes 2…

but i was thinking… maybe the button (which is a simple image) is “hardlinked” to the first record of the recordset?

I had to leave work and can’t work on the DB now… But i’ll get to it soon…

thanks you all for the help!
 

disgracept

Member
Local time
Today, 22:10
Joined
Jan 27, 2020
Messages
30
It is the image.

I placed an image and a button on a continuous form, each with a click event to MsgBox the record ID.

Clicking image only picks up the ID of the first record, whichever record is clicked.

Clicking Button shows correct ID as expected.
Right! I was just wondering it might be the image! (was typing preciosa post and only saw this one after submiting…)

i’ll put a button instead of an image…

thanks guys!
You were an amazing help!
 

Users who are viewing this thread

Top Bottom