VBA code to open the insert object and bring you to the browse point

  • Thread starter Thread starter MartinR
  • Start date Start date
M

MartinR

instead of right clicking and scrolling down the list and then clicking
on insert object and following the steps, is there code that i can put
behind a button that will bring me directly to the browse part of the
insert object screen?

Any suggestions?
 
Hi, Martin.
is there code that i can put
behind a button that will bring me directly to the browse part of the
insert object screen?

Yes. Try:

Private Sub InsertBtn_Click()

On Error GoTo ErrHandler

Me!frameOLEObj.SetFocus
SendKeys "%F%B", False
RunCommand acCmdInsertObject

Exit Sub

ErrHandler:

If (Err.Number = 2501) Then ' User cancelled.
' Do nothing.
Else
MsgBox "Error in InsertBtn_Click( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
End If

Err.Clear

End Sub ' InsertBtn_Click( )

.. . . where InsertBtn is the name of the button and frameOLEObj is the name
of the control bound to the OLE object column.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
When i put that code in and changed the names to the same as on my
form, i am getting a message saying

"The command or action 'Insert object' isn't available now"

What might be wrong?
 
Hi, Martin.
What might be wrong?

Is the control a bound object frame? Is the bound object frame enabled and
not locked? Is this frame bound to a column with a data type of OLE Object?
These are the default properties of the control needed to insert objects on
a form, and they are all requirements for the suggested code to work, so
don't change these defaults.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
all those settings are correct, but i am still getting the same
message.

can you also please tell me what the line SendKeys "%F%B",
False does?
 
Hi, Martin.
all those settings are correct, but i am still getting the same
message.

Perhaps it's one of those things that only works in some versions. It works
with Access 2003 SP-1.
can you also please tell me what the line SendKeys "%F%B",
False does?

It's the equivalent of pressing <ALT><F> and then <ALT><B> and not waiting
for further user input.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top