I'm trying to create a form with the following behavior:
Clicking it when it's empty opens the dialogue window of inserting a hyperlink
Clicking it when there's a hyperlink opens the hyperlink
Clicking a nearby "Clear" button clears the form deleting the hyperlink (if present)
I'm currently stuck with step 2. The code for hyperlink insertion window is this one:
Private Sub PSIC_Click()
Me.[PSIC].SetFocus
On Error GoTo browse_stop
RunCommand acCmdInsertHyperlink
browse_stop:
End Sub
When I try to apply different if then variations it doesn't work as expected. Either I fail in properly applying if then or in determining that the form is empty.
The OnClick() event of your hyperlink textbox would be:
Private Sub PSIC_Click()
On Error GoTo browse_stop
If ISNULL(Me!PSIC) Then
RunCommand acCmdInsertHyperlink
End If
browse_stop:
End Sub
I removed SetFocus because clicking on the textbox should automatically set the focus, but if you need it there for some other reason it wasn't really hurting anything.
The "Clear form" command button's OnClick() event would be:
Private Sub cmdClearForm_Click()
Me!PSIC = NULL
End Sub
To open a hyperlink from a form in MS Access:
In Design View make sure that the hyperlink is in its own text box and then go to the 'property sheet' then half way down you should see the option for Hyperlink Address. In here add the address of the hyperlink.
If you want to click on an image and have it open a hyperlink then right-click on the image go to hyperlink.
Related
I just found something strange with MS-Access 2016. I have a database with 2 forms: one hidden, one for a menu. The autoexec will open the hidden form and that one will open the menu form.
I unchecked some options, under Current Database e.g. [Display Navigation Pane] and [Allow Full Menus].
I have an exit button/command on the menu form. On Click, it calls DoCmd.Quit. But before exiting, I am getting an MS-Access window asking for the parameter that is normally when the form open, not when it is closing.
After doing a lot of testing and I mean a lot, I realised that the problem is related to the fact that I am disabling the [Display Navigation Pane]. If I keep the navigation pane, but instead I unchecked all Object Type, then everything works correctly.
So, my question is why disabling the navigation pane can create something like that and is there a way to fix it?
Yes, my solution works, but I don’t like it since users can open and close the navigation pane using the shutter bar; nothing shows but it is still distracting and users can call for support.
The problem is not related to the fact that the first form is hidden, but because it is open. If I add a DoCmd.Close acForm, “F_Parameter” before my DoCmd.Quit then it works.
It is easy to reproduce the problem:
Create a new database
Create two forms:
F_Parameter
F_Menu
Create a Macro named Autoexec:
OpenForm
Form Name: F_Parameter
Window Mode: Hidden
In form F_Parameter create an event On Load
Private Sub Form_Load()
DoCmd.OpenForm “F_Menu”
End Sub
In form F_Menu create a Button named Btn_Exit with an event On Click
Private Sub Btn_Exit_Click()
DoCmd.Quit
End Sub
In form F_Menu create an event On Load
Private Sub Form_Load()
MsgBox “Hello”
End Sub
go File, Options, Current Database and
uncheck Display Navigation Pane and
uncheck Allow Full Menus
Save, exit and open the database:
You will get a “Hello” because the F_Menu form open, now click on the exit and you will get another “Hello”. This second one should not be there because the form should be closing not opening.
I was able to reproduce the issue described. I don't think it has anything to do with the Navigation Pane.
This is happening because while the DoCmd.Quit event is occurring, the hidden F_Parameter form is becoming "unhidden" in order for Access to close it. This causes the F_Parameter Form.Load event to run, which is essentially opening F_Menu, thus causing the Form.Load event on F_Menu to run.
I was able to solve this by first explicitly closing F_Parameter, then quitting:
DoCmd.Close ObjectType:=acForm, ObjectName:="F_Parameter", Save:=acSaveNo
DoCmd.Quit
Im pretty new to programming for MS Access and Visual basic. I'm trying to create a form that will change what the subform is based on a toggled option press.
I have attached pictures of the simple form I'm trying to do and gotten some code off tutorial sites that have shown an example of how to do it but I'm not sure if I should have the subforms pre-created or make the button load the form when clicked.
Option Compare Database
Private Sub Option0_Click()
End Sub
Private Sub Toggle11_GotFocus()
Form1!Testform1.SetFocus
End Sub
Private Sub Toggle12_GotFocus()
Form1!Testform2.SetFocus
End Sub
I know this code isn't all that's needed but I can't seem to find a good place to start to find out what needs to be done with this.
Newer versions of Access seem to hide subform tabs when you open a form, but there is a tab stop property for the childforms. I set the property for that to yes and then for one of the child forms to set the tab index to 0 and the other to 1. You can toggle between the forms using Ctrl Tab when you do this. If the Child Form tabs are not visible when you open the main form, Ctrl Tab will also make them visible allowing you to click on the tabs.
I have a form in Access like this:
When I click on "Order" button, I want to order the "client" table (shown in the bottom) order by "firstname". How I can do? Can I use macro or I must use VBA code? So far I have only used macro, I never used VBA.
You can use VBA in the OnClick Event.
Click on your button while in Design View. Then go over to the properties and go into the Event tab, click in the text box for the On Click Event. Youll see a button with 3 periods appear. Click that and select the Code Builder.
It will bring up a Sub like the below. Just put that line of code in there and your done.
Private Sub OrderButton_Click()
DoCmd.SetOrderBy "[FieldYouWantToSortBy]" DESC, ""
End Sub
Done. I used a macro with "SetOrderBy".
I have a form which has some fields which have conditionalformats which are linked to values which get entered via a zoom in box. In other words, to update each conditionally formatted field, the user clicks on the control and a zoom in box appears allowing the user to enter the data. In the following situation the conditional formatting takes effect only after i close the main form and re-enter. In other words, it does not update automatically once the user access the zoom in form. I tried to put a refresh command on the close zoom in form event, but it is giving me an error. Below is the code i put on the close event of the zoom in:
Private Sub Form_Close()
Forms("frmprojectphasemasterboard").Form("frmprojectphase")!Description = Me.txtZoom
Forms("frmprojectphasemasterboard").Form("frmprojectphase").Refresh
End Sub
Forms!frmProjectMasterBoard!frmProjectPhase.Form.Refresh
I'm creating forms with VBA/Access to access my database.
In a form, I have a *lst_sinistres* listbox that displays the results of my SQL query and when I doubleclick on one of the results it opens me another form with thanks to this code
Private Sub lst_sinistres_DblClick(Cancel As Integer)
DoCmd.OpenForm "F_SINISTRE_MRH", acNormal, , , , , Me.lst_sinistres.Value
End Sub
I wanted to change my form, and add tabs to make it more ergonomic. So I placed my *lst_sinistres* listbox inside a tab.
The problem is that when I doubleclick on one of the results in this listbox (now placed in the tab), the form *F_SINISTRE_MRH* does not open.
Does someone have an idea of where the problem might come?
Thank you
A quirk of VBA control events is that event code can become detached from the control object. Things that cause this tend to be re-naming controls and copy/pasting similar code between controls. To move your listbox onto a tab control you needed to cut and paste it temporarily. That broke the link between the written code and the object name. When the code and object are properly linked, [Event Procedure] shows up in the property sheet (as suggested by #4dmonster).
If you are in the VBA editor, choosing Debug->Compile will search through all the code and re-link event code with like-named controls. This step is worth a try before re-writing because you may end up with orphan blocks of
Private Sub OldControlName_DblClick(Cancel As Integer)
MsgBox "Why don't I work anymore?"
End Sub
that are treated as Form-level subroutines that just happen to never be called.
pT