How to open object(macros) and use the form in it using command button? - vba

Hi GUYS , I will explain my problem:
1- I use object command in excel to bring another excel file see image(1)object_image
2- I want to make command button which links to the object
3-image (2) show the worksheets and forms note when I close the book, the object's book change image all
so what I want is when I click the command button in my first excel it will open the form and allow me to change in the second excel.
this is my code
Private Sub CO1_Click()
Workbooks("Book3").Worksheets("Sheet1").CommandButton1.Value = True
Application.Run Workbooks("Book3").Worksheets("Sheet1").OnAction
trainUserForm.Show
End Sub
please, guys, i need this to finish my work and thx :)

Related

Get value from command button VBA

I have created A userform with few command buttons.
I can't seem to figure out how do I get the information from them.
I want to open this userform from another one and then I want the user to choose an option from one of the buttons which will change a specific cell in the table itself
the userform I created
I did not write anything on this userform therefor there is no code from it to show only the design.
how do get the information from the buttons to be written in A specific cell on a specific worksheet?
double click on one of the buttons, in the code menu a new sub should appear. this looks something like:
Sub CommandButton1_onClick()
End sub
Alongside this event method, it also has a few properties. The one that is usefull here is the CommandButton1.Value, this represents the state of the button (either true or false iirc).
So build for each button (I strongly advice giving them custom names to prevent getting lost in the trouble) as sub like this:
Sub CommandButton1_onClick()
if CommandButton1.Value then
ThisWorkBook.WorkSheets("WorksheetName").Range("YourRange").Value = "Some value"
else
ThisWorkBook.WorkSheets("WorksheetName").Range("YourRange").Value = ""
end if
End sub

vba macro list box not letting editing some macros

I have an Excel project with a lot of macros.
What I want is assign macros to buttons in the ribbons.
For that I created macros like:
Sub R10_parallel_device()
help.helpON ("parallel_device ")
Call sub_novelty_claims("parallel_device")
End Sub
So the three conditions are met:
a) the macro SUB R10_parallel_device() do not accept parameters
b) it is not private
c) It is not hide
when I go to the list of macros I see all the list of macros named Rnn but all THE BUTTONS ARE GREY OUT EXCEPTFOR CREATE.
Now if I click in that sub for instance SUB R10_parallel_device() I can not edit it and if I click "create" excel sends me to a new created module where
Sub R10_parallel_device()
End Sub
appears.
&
When I go to file/options/ribbon if I want to add that macro to a button it is listed and it is possible to assigne the macro to a button but it would not run, giving the error that such a macro is not found.
NOTE: I checked which macro are listed thisworkbook/all/ etc.
note2: this did not help me. this neither
thx
Confirmed it's the macro names - go to Developer -> View Code (or type Alt + f11), then select the module with your code in it and rename them. For whatever reason it's that R# syntax:

Can i launch userform from a button in a Sheet

Pop up charts in VBA Excel
I was very curious with the answer in the above link.
My question is, Can I pop up a graph with click of button(The button is on Sheet1) and when i go bach to
Sheet thr graph is gone
Pertinent to your question as it is worded in the Title (i.e. 'Can i launch userform from a button in a Sheet'), you can implement this functionality in two simple steps:
1). From Excel 'Developer' tab select Insert -> Button. By default, it will create a new Button1 and corresponding Click event handle will be added to the Module1
Sub Button1_Click()
End Sub
2). Provided that you have a User Form named UserForm1, add a single statement in that event handle that will open the UserForm1 on Button click:
Sub Button1_Click()
UserForm1.Show
End Sub
In case you are trying to implement additional functionality, please include your code snippet highlighting the problematic part.
Hope this will help. Best regards,
Let's do it by point and basing on the answer you have posted.
Can I pop up a graph with click of button(The button is on Sheet1)?
Yes, you can. You need to:
Put a Button on Sheet1 and associate to it a macro, let's say popUpChart;
Create and show the chart:
Sub popUpChart()
Dim ch As UserForm1
Set ch = New UserForm1
'ch.CommandButton1_Click()
'a) Uncomment the line above if you want to invoke the button press before to show the chart
'b) If you decide to uncomment, remember to change the sub from "Private" to "Public"
ch.Show
End Sub
when i go bach to Sheet thr graph is gone
I don't understand well what you mean here. Do you mean "I want the graph to be gone when I go back to the sheet" or "I would like the chart to stay here but actually it's gone?
a) In the first case, it's enough to remove the image from the Image control of the form;
b) In the second case, it's enough to remove the Set statement from the button's macro.

Open multiple copies of word form?

I'm fair at Access vba but Word is a new dialect for me.
I work for a hospital that has an Electronic Medical Record (EMR). We need a specific format and structure for the Nurse’s Clinical Progress Notes that can’t be created and enforced in the EMR. I created a Word vba UserForm, "frmProgNote" attached to a document "ProgNote.doc". FrmProgNote" has textboxes that create the structure we need for documentation and there is a command button that when clicked sends the info from the form to bookmarks in ProgNote.doc and copies all text from the document, including the newly inserted text onto the clipboard. The user then pastes it into the EMR. This all works great (believe it or not) but now they want to have multiple copies of frmProgNote open at the same time so they can move between several patients at once.
I’ve worked on this for 2 days and just can’t get it. I found I could not open multiple instances of Word and have the same form open in more than one. I copied the document and form so now have ProgNote1.doc with frmProgNote1 and ProgNote2.doc with frmProgNote2. I can get both to open BUT if I open frmProgNote1 then open frmProgNote2 the only data I can copy comes from frmProgNote2; the copy button doesn’t copy anything from the first form. I can click on frm1 and get it to take new data but the copy button doesn’t work anymore. Any suggestions? Thanks so much.
The following code gives the basis for creating a new instance of a UserForm.
Private frmNewInstance As Object
Private Sub CommandButton1_Click()
Set frmNewInstance = UserForms.Add(Me.Name)
frmNewInstance.Show
End Sub
Private Sub UserForm_Terminate()
Set frmNewInstance = Nothing
End Sub
It is necessary to control the object-reference, setting it to Nothing when the form instance is closed.
Note that this process is not as robust or reliable as it would be in, for example, VB.NET or C#. In particular, it is more difficult to distinguish between the different instances of the form.
One approach to consider is to use the Tag property of the form:
frmNewInstance.Tag = "OtherOne"
frmNewInstance.Show

Access 2010 Me.Refresh/Me.Requery

I have a form that I want refreshed when the submit button is clicked. Preferably those that have default values will be restored and those without will be blank.
The submit button has an attached OnClick Macro that, checks to make sure all fields are filled, if so an action query runs that inserts a new row into a table.
So its after this action query that I want the refresh to occur. I have tried researching and come across suggestions that suggest using VBA code Me.Requery or Me.Refresh. I'm not 100% on how to incorporate this into the macro. The RunCode command doesn't recognize the function I put the code in, and The convert macro to VBA option in the top left is grey'd out.
I'm new to Access and just not seeing where the communications are for code and macros if someone could please elaborate for me I would be greatly appreciated.
Please consider my solution as a brief introduction to VBA. If you care to learn the language, you will find there is very little you cannot do.
Within your submit button properties, there should be an 'Event' tab. In this tab, the On Click should be set to [Event Procedure]. Click the three dot button just to the right of that, and it will launch the VBA editor.
All you need to have here between the Private Sub and End Sub lines are these lines of code:
DoCmd.RunMacro ("Mac_1")
Me.TextBox1.Value = "Null"
Me.CombBox1.Value = "Null"
Me.Refresh
MsgBox "Your Save Was Successful.", vbOKOnly, "Saved"
"Mac_1" is the name of the macro you want to execute. the ME.Refresh executes as soon as mac_1 finishes, and will refresh the page. Be sure to enclose it in a proper quote (") and not a double tick ('').
The Requery command can be used from both within VBA code or a macro. It sounds like you are using the macro designer so you can use the Requery macro action instead of VBA.
Just add this to your macro after you have inserted your new data.
This macro action lets you specify a control to requery. The parameter can be left blank to requery the source of the active object. More information can be found here.
Edit
In response to your comments, I think you should try experimenting with the SetProperty macro action (more details here).
I have attached this macro to a button click event and the value from the TextBox called txtInputValue is cleared. The Value field is left blank as you want to fully remove the value from the text box.