Ribbon go to specific record

raphael99

Registered User.
Local time
Today, 01:40
Joined
Apr 6, 2015
Messages
126
Hi
on a ribbon
I set up a button which I would like to open a specific record. From a form I use happily:
Code:
DoCmd.OpenForm "frmDetail", , , "recordID = " & Me!recordID
and it works.
But when I do from the button on the ribbon it does not.
Any help?
 
Last edited:
on the ribbon it does not
why not? you get an error? nothing happens? have you stepped through the code?

the only suggestion I have is the 'Me' collection is only available from within the form.

so try

DoCmd.OpenForm "frmDetail", , , "recordID = " & forms!myform!recordID
 
If for
Code:
frmDetail
i set up the name of the form should be open then waht name in myform
Code:
forms!myform!recordID
shall I use?
I tried with same name of FrmDetail with no avail
 
if you have tried

forms!frmDetail!recordID

and it doesn't work, perhaps it can't be done from the ribbon. Suggest keep your button on the form
 
It gives error 2450. "impossible to find myform" where myform has the same name of frmdetail
But it can be done. I'm sure cause I got an access commercial software does
 
impossible to find myform
why would you think I know the name of your form when you hadn't told me what it was? and given the error - what does that tell you?
 
why would you think I know the name of your form when you hadn't told me what it was? and given the error - what does that tell you?

Here it is as I wrote:
Code:
DoCmd.OpenForm "MascheraAnagrafica", , , "ID = " & forms!MascheraAnagrafica!ID
 
I think the issue here is whether you have setup your callbacks properly.

Does the code even fire? Try a Msgbox and see if it fires.
 
I think the code fires, because he has an error 0- It gives error 2450. "impossible to find myform"

he then provided a different form name - frmDetail

and now he is opening a form 'MascheraAnagrafica' which already has to be open because "ID = " & forms!MascheraAnagrafica!ID

So I'm now totally confused:confused:
 
The callbacks seem wellsetted. I tried to open a test form and it is working. Also are working the msgbox from the author of ribbon creator
 
Hmmm... I see, good point. Let's see what Raphael says. I just thought I should highlight that just in case.
 
Hi good news. I got an answer.
The trick was to getting the ID from another form like this:
Code:
DoCmd.OpenForm "MascheraAnagrafica", , , "ID = " & forms!MascheraPrincipale!ID

Thanks for the right suggestion.
Hope this can help someone
 
That's strange! I would be interested to see why this didn't work so if you've got a minute upload a cut down version of your form with the problem code.
 
I didn't have any problems with the button raphael99. You just need to make sure that the MascheraPrincipale form is open before you click the button. If the form is not open, it will error.

Sorry, I didn't understand. Can you explain that differently?
 
Sure.
If MascheraPrincipale or other forms are not open, you cannot access to MascheraAnagrafica clicking on the ribbon's button. I would like to add some code for popup a msgbox warning the user to choose a patient before. I got some code from elsewhere:
Code:
  If IsNull(Forms!MascheraPrincipale!id) Then
    MsgBox "You must choose a patient before clicking this button", vbOKOnly, "Missing data ..."
    Forms!MascheraPrincipale!id.SetFocus
  Else
    Select Case control.id
              
        Case Else
            DoCmd.OpenForm "MascheraAnagrafica", , , "ID = " & Forms!MascheraPrincipale!id
    End Select
  End If

End Sub

But it gives error "2450: impossible to find MascheraPrincipale"
 
No, you can't. A form is like a door/window/access point and if that door isn't open, you can't access/see what's inside. Error 2450 is telling you that MascheraPrincipale is not open! It must be open before you press the button.

For the condition, change IsNull to this:
Code:
If Len(Forms!MascheraPrincipale!id & vbNullString) = 0 Then
... but again, it won't work if MascheraPrincipale is not open.
 
The code you have plus the enhancement I gave you in my last post does just that.
 

Users who are viewing this thread

Back
Top Bottom