Hyperlink "deactivated" after VBA on textbox - ms-access

I've been using VBA and available modules to integrate the browse for directory and browse for file functionalities in two different MS Access projects. Here are the example files where I took the functionalities from:
Browse to folder: http://www.lebans.com/callbackbrowser.htm
Browse to file: http://www.access-programmers.co.uk/forums/showthread.php?t=97787
In both my .mdb projects, I have tried to browse for a file/folder, then output the address to a hyperlink textbox, linked to a hyperlink field in a table.
It has mostly worked, but unfortunately, with both these functionalities, the hyperlink stops working... The output to the textbox and to the table seems perfect, but when I click on the hyperlink, it does not take me to Windows Explorer.
To make the hyperlink work, I have to double click on the textbox, (which then lets me edit the field) remove the last letter, then type it back again, and tab out. Then, when I click, Windows Explorer opens normally, as a hyperlink should.
What is the solution? I've already tried:
DoCmd.RunCommand acCmdSaveRecord
Without success...
Thanks for your help

If I understand you correctly, you want to open an explorer window for a specified directory set in the textbox?
If so, you'll need to use the textbox on-click event, something like this:
Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Shell "C:\windows\explorer.exe """ & TextBox1.Value & "", vbNormalFocus
End Sub
Or, you can use the double-click event:
Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Shell "C:\windows\explorer.exe """ & TextBox1.Value & "", vbNormalFocus
End Sub
By the way, I could only test this in Excel - I don't have Access installed, but it should be the same.

I found the answer to my question on stackoverflow:
Access - Hyperlinks Aren't Linking
Turns out you need to concatenate #'s before and after the hyperlink address for it to work properly as a hyperlink.

Related

MS Access - Command button wont function at all

I have tried to Google and review previous Stackoverflow posts but I cannot seem to find a solution and this seems like such a simple fix.
I put a Command button in my Form because i wanted to test exporting information within the form to an Excel spreadsheet.
Private Sub cmdExportFilename_Click()
Dim sFilename As String
sFilename = "C:\Users\Redacted\Desktop\exportResults.xlsx"
DoCmd.OutputTo acOutputQuery, "OpenComplaintsQuery", acFormatXLSX, sFilename, AutoStart:=True
End Sub
I made sure the OnClick event was set to [Event Procedure] but when i go into form view and click nothing happens not even an error so i feel like i am still missing something that is telling that button to run that code. i checked my Trust Center settings and changed it to enable code but still nothing.
Any advice is helpful!

Access 2016 set form field based on previous form value

I am creating an Access Database formed out of two things - Software and Licences. Licenses are attached to Software via their ID.
I have a form created for Software, and would like to create a button that, when clicked, opens a fresh "Add License" form which pre-populates the Software ID and that people can fill in the rest of the information on.
I've been using Macros from a similar Office 2016 Template and it continually falls over when trying to put this information into the new License form.
I've attached a screenshot of my macro below - I've gone through many iterations of this now and the error I get is 30024, which appears to indicate that it cannot find the field to put the SoftwareID into in the newly opened form.
I've also set the "Control Name" to just "SoftwareID" as this was also suggested elsewhere but this also does not work.
Any suggestions?
Screenshot of Macro in question
I couldn't get it to work using the embedded macro so I used a VBA macro instead which worked :). To do this (assuming you haven't done it before):
Open your "Software" form in design view
Show the property sheet (Ribbon -> Design Tab)
Click on your button
Click the "Event" tab on the Property sheet
Delete the "On Click" event
Right click your button and click "Build Event"
From the "Choose Builder" popup box, click "Code Builder"
Assuming you don't have any other macros, your code should look just like mine with the only differences being the name of your button (mine is Command163)
p.s. I Couldnt get the code tags to display properly so i just added some line breaks. Apologies for the improper indenting.
Option Compare Database
Private Sub Command163_Click()
DoCmd.RunCommand acCmdSaveRecord
openFreshAddLicenseForm (Me.ID)
End Sub
Public Function openFreshAddLicenseForm(ID As Integer)
On Error GoTo Macro1_Err
DoCmd.OpenForm "Add License"
DoCmd.GoToRecord , "", acNewRec
Forms![Add License]!SoftwareID = ID
Macro1_Exit:
Exit Function
Macro1_Err:
MsgBox Error$
Resume Macro1_Exit
End Function

MS Access Office 365 keeps crashing when opening a popup form

I am using a windows 7 Enterprise 32-bit operating system and Microsoft Access 365 ProPlus.
I open a form then when I double click on a field it triggers an event procedure that opens another form. This form is a Pop Up form (non model) single form default view. Everything was working great for the last year or so and for some reason when I open the form this way the access program crashes.
I can open the form by selecting it from the search forms dialog.
What I found works is I need to open the form then edit it in design view. Make a small change in the form and save it. Then view it in form view and close the form. Once I have done all this I can run my program normally and everything works great until I close access and re-open it. Then I need to do it all over again.
I have ran the compact and repair tool several times.
My code is a very simple one:
On Error GoTo Err_Command18_Click
Dim intBuildingId As Integer
Dim StDocName As String
intBuildingId = Form_Frm_Buildings.Building_ID
StDocName = "Frm_Buildings_To_Frm_Manager"
Me.Refresh
DoCmd.OpenForm StDocName
Forms(StDocName).Recordset.FindFirst "Building_Id = " & intBuildingId
Err_Command18_Click:
Exit Sub
Any help would be appreciated and thanks in advance!
Mark

take a snapshot with a webcam from ms access form

i need to take a snapshot with webcam when someone press a button in access form.
Is it possible?
i know how open a program from access but i'm stuck on how to trigger the event
the code
Private Sub Command1_Click()
Dim stAppName As String
stAppName = "C:\Program Files\myapp"
Call Shell(stAppName, 1)
End Sub
now let's say the snapshot trigger by f12 key in the app
how do i get the f12 key to click automatically
ok i got it
if any one want to know here is the method
1.by 2 macros "runapplication" & "sendkeys"
with "runapplication" just put the path of the app
with "sendkeys" just put the command SendKeys "{yorkey}"
by the way you need to press show all command in the the toolbar
or you can do it in vba code
You could try this if you are in windows 8/8.1
Dim cameraPath As String
cameraPath = "shell:AppsFolder\Microsoft.MoCamera_cw5n1h2txyewy!Microsoft.Camera"
Shell "explorer " & cameraPath

MS Access 2010 - Prompting user to save changes

I have developed a form and I would like to prompt the user to save changes before they navigate away from the modified record.
If the user attempts to navigate away, I want a prompt to appear asking if they wish to save changes, upon which they may select "Yes" or "No".
I have been informed that the Before Update event is the one I need to focus on, but I keep receiving the "the expression before update you entered as the event property setting produced the following error" message.
These are the steps I take before reaching the error:
Change view to Form View
Make a change anywhere in the record via the form
Attempt to navigate away from form via navi-buttons that I put into my form (which work just fine if no changes are made but which fail to do anything if a single change has been made)
Nothing happens, so I revert to Design View, to receive the following error notification
I press OK and then receive this message:
And then I go back to Square One.
Furthermore, any Conditional Formatting has stopped working altogether since this problem has arisen; I do not know for certain if the two are linked, but thought it worth mentioning.
Any ideas how this can be achieved (ideally error-free)? Unfortunately, I cannot post my system up as it deals with highly confidential data.
UPDATE:
I have tried a variety of codes which I have modified, all to no avail. At present, I have removed any such code altogether, but the code I have tried in the past is something to the effect of:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
On Error GoTo Err_BeforeUpdate
If Me.Dirty Then
If MsgBox("Do you want to save?", vbYesNo + vbQuestion, _
"Save Record") = vbNo Then
Me.undo
End If
End If
Exit_BeforeUpdate:
Exit Sub
Err_BeforeUpdate:
MsgBox Err.Number & " " & Err.Description
Resume Exit_BeforeUpdate
End Sub
The default behaviour for a Microsoft Access bound form is to automatically save the record whenever the user does the following:
Moves to another record, Closes The form or explicitly clicks the save button on the ribbon
Therefore I thinks it may be redundant asking the user to confirm if they wish to save.
The forms before update event is generally used for validation so you can check the data that has been entered into the controls and decide in code whether to allow the data to be saved.
To prevent the data from being saved you would change the Cancel variable for example:
Cancel=True
MsgBox "There is a problem with the data entry", vbExclamation, "Please Check Your Data"
The user would then have to press escape or click Undo on the ribbon to escape out of edit mode
Regarding the error you are getting please look into and try the decompile switch documented at the following web page:
Decompile Switch
I occasionally get errors when working with and saving VBA code over and over. Doing the decompile can usually fix this problem. However make sure you do a backup of the database before you start.
Also you could try exporting out your form as a text file and then importing it back in again using the following code which will help if the form has become corrupted:
Application.SaveAsText acForm, stringFormName, stringFolderName & "\" & stringFormName & ".txt"
Application.LoadFromText acForm, stringFormName, stringFileName
Open your form in Design View
Right-click on the form and click on "Properties" from the pop-up menu
Scroll down to the "Before Update" event
All the way on the right you should see a box with an ellipse ("...") in it. Click that box to open the code associated with the Before Update event.
If it opens to a blank sub, you haven't assigned the event properly. Make sure the event is called "BeforeUpdate" (one word) and not "Before Update" (two words).
Your error indicates that this is likely the cause of the issue.