Hyperlink button to open a file - forms

I have a Table (Table1) with a list of PDF files, and its Form (Form Table1).
In "Table1" I have a hyperlink field (PDF) and I want a button in "Form Table1" to open that hyperlink. I tried to select this button, go to Event>On Click>Code Builder and type
Private Sub Command1_Click()
Application.FollowHyperlink PDF, , True
End Sub
What is the correct method I should be using to achieve this?

An easy way would be referencing the pdf file's location by referring to the HyperlinkAddress using some VBA. Put this code on a button or whatever event you please:
Private Function Get_Link()
Me![mybutton].HyperlinkAddress = _
Nz(DLookup("[filename]", "[my_files_table]","[my_files_table].[id]=" & Me![id]), "")
End Function
To update the hyperlink you can refer to the Hyperlink's ID or primary key in a form by firing an event like: OnCurrent: Get_Link()
This would retrieve the current ID on your form and use that to get the hyperlink you want.
Reference: Bytes.com

Related

USERNAME-VBA-ACCESS

I have been asked to create a field(FORM) in access that get the USERNAME who has logged in . I created the string VBA Me!EmployeeID = Environ("USERNAME") which is on load. However, I noticed when I click on next record it goes way and wont get updated. I am not VBA expert that why I am here. What string should I write and where should I put it?
Should it be on form properties or the Employee ID field properties and also which part Before update or After?
Use form Current event. This event occurs both when a form is opened and whenever the focus leaves one record and moves to another
Private Sub Form_Current()
Me!EmployeeID = Environ("USERNAME")
End Sub

Open Form to a value selected on ComboBox - Ms Acces

I want to open a form to a specific record based on the value is selected on a comboBox. I have written a code and its working, but before opening the form it shows a dialogue box with input field asking for the parameter i want for the form which i dont want the VB code to ask.
DoCmd.OpenForm "Final_Exam", acNormal, , "[admclass] = " & Me.Combo4.Value & ""
This is the code i have written and the requirement is that on clicking the button the form opens without any dialogue box asking for parameter. thanksa
What I've found is the best way to open one form from another is to use OpenArgs. When opening Form 2 from Form 1's button, use code like this:
Private Sub cmdOpenOtherForm_Click()
DoCmd.OpenForm FormName:="frmOtherForm", OpenArgs:=Me.Combo4.Value
End Sub
Then, in the Load event of Form 2, use the openargs to set up your filter:
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me.Filter="[admclass]=""" & Me.OpenArgs & """"
Me.FilterOn = True
End If
End Sub
If the field you're filtering on is a text field, make sure to properly escape double quotes (as is done above).

Access Form Go To Record

In Access, I have a main form with a listbox. The listbox is used to navigate to different records on the main form. The main form also has a button with the following code to open a dialog form on which I add a new record.
Private Sub New_Btn_Click()
DoCmd.OpenForm "New Issue", , , , acFormAdd, acDialog
Requery
Me.ID_Box.SetFocus
End Sub
After I close the dialog form, I want the listbox to update and to select the new record that added on the "New Issue" form AND I want the main form to navigate to the new record.
I cannot figure out how to make either of these actions occur. Please help me find the best method for these steps.
Assuming the listbox has a rowsource, you can requery the ListBox to show the new record like this:
ListBox1.Requery
Then to move the 'main' form to the latest record (assuming the ID/PK is an autonumber field, which is how the form recordsource is sorted):
DoCmd.GoToRecord , "MainFormNameHere",acLast
If you don't have an ordered recordset, you can use
Me.Recordset.FindFirst "PrimaryKeyField = " & NewRecordPK
Where NewRecordPK is a variable with the new records primary key stored.
You could call this from the dialog if you like. Just make sure you save the record first using something like Docmd.Save Then,
Forms!frmMainForm.Form.Recordset.FindFirst "PrimaryKeyField = " & Me.PrimaryKeyField

How to get a value from text box in form 1 to another

I have a form witch is a calculator i want to post the answer of calculator to form2
When i click the button post it show next form but it can not post the value
Private Sub cmdpost_Click()
Me.TXTnumber.Copy
UserForm2.Show
UserForm2.TextBox3.Paste
Me.Hide
End Sub
Is there a reason to Copy Paste these?
If TXTnumber is a named textbox won't this work for you?
UserForm2.TextBox3 = Me.TXTnumber
UserForm2.Show

MS Access 2007: Programatically add hyperlink to a form with VBA

A form populates and the OnLoad event tests for the value in a field. If that value is blank, then I want a hyperlink to appear in place of the textbox which I have figured out. The hyperlink needs to link to another form within the database which is my question.
Take the following snippit:
If cp = "" Then
Forms[!MyForm]![MyTextControl] = "Update"
Forms[!MyForm]![MyTextControl].IsHyperlink = True
' what is the code to add the link to the other form
Else
Forms[!MyForm]![MyTextControl] = cp
End If
Any thoughts on how to create a hyperlink that links to another form?
The text for a hyperlink in a textbox is:
="Form##form table1_form#This will open a form#"
="Display text#Address if required#sub address, eg form or report#screen tip#"