Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox

Status
Not open for further replies.

ugaint

Technical User
Jun 5, 2006
4
US
Ok, new to MS Access and need some help. I want to be able to have a hyperlink that once clicked, checks a checkbox and then records the date/time. I created a table called "Check" with the following:

Field Name Data Type
UrlID Primary Key Autonumber
Hyperlink Field Hyperlink
Checkbox Yes/No
Update Date/Time

What do I do from here? You may have to be specific about the code as I know very little about VBA.


 
Is the hyperlink going anywhere?

I have a label that does something similar when you click it. (But it doesn't act as a hyperlink, of course.)

Here's the code from the form's module:
Private Sub lblEffDate_Click()
If chkEffDate.Value = 0 Then
chkEffDate.Value = -1
Else
End If
End Sub

It should be easy to modify this code like this:
Private Sub Hyperlink_Click()
If Checkbox = 0 Then
Checkbox = -1
Update.value = Now
Else
End If

End Sub

But I don't know how the hyperlink part works. Good luck!
 
This is the code I'm using. I put it in the AfterUpdate field in the Properties section of the checkbox.

Private Sub Checkbox_AfterUpdate()
If Update_Check.Checkbox = -1 Then
Update_Check.Update = Now()
Else
Update_Check.Update = Null
End If

End Sub
 
I would like to be able to click a hyperlink and then upon doing so, a check is placed in a checkbox and field that displays the date and time is updated. The point would be to keep track of when and if people have used hyperlinks.

 
I see.....

Have you tried using the onclick event of the object containing the link... so when the user clicks.. runs a sql adding a time of click user that clicked etc....

I believe this is fairly easy..... and I think it would work, no need for checkboxes...

your thoughts???
 
That sounds good. How do I do this (I'm new to access)?
 
First you will need to know which user clicked teh link... i suppose you have a mdw related to this database.

So create a field called UserName as txt

Create a invisible txtbox you will call PassThruDate, Bound PassThrough to update (i suggest changing Update to UpdateDate),

bound another invisible txtbox, PassThruLink to Hyperlink Field

and last bound invisible PAssThruUser to UserName

lets suppose your hyperlink is a label... right click the label, properties go to event, on click, Select the 3 dots.. select by code, it will bring you to VBA immediate window

you should see something like this:

Code:
Private sub label1_click()
PassthruDate.txt = Now
PassThruLink = "Enter the link clicked here"
PassThruUser = CurrentUser()
Refresh
End sub

This is one way to do it, going through SQL wouldve been more straight forward, but harder for you to understand I think, if u want to go through SQL heres what you should enter:
Code:
Private sub label1_click()
Dim strsql as string

strsql = "UPDATE [highlight]TableName[/highlight] " & _
         "SET UpdateDate = " & Now & ", " & _
         "UserName = " & currentUser() & ", " & _
         "[HyperLink Field] = 'name of hyperlink entered'"
DoCmd.RunSql "strsql"

End sub


Note that TableName should be the name of your table, and UpdateDate is if you changed the name of your field Update to UpdateDate....

both of these method should work, the 2nd one being better.

 
I corrected something in the last coede
Code:
Private sub label1_click()
Dim strsql as string

strsql = "UPDATE TableName " & _
         "SET UpdateDate = [red]#[/red]" & Now & "[red]#[/red], " & _
         "UserName = [red]'[/red]" & currentUser() & "[red]'[/red], " & _
         "[HyperLink Field] = 'name of hyperlink entered'"
DoCmd.RunSql "strsql"

End sub
 
I am sorry looks like I was using the wrong statement, it would be a INSERT INTO Instead of UPDATE

lets say the order is in table is
UserName
HyperLink Field
UpdateDate

Code:
Private sub label1_click()
Dim strsql as string

strsql = "INSERT INTO TableName (UserName, [HyperLink field], UpdateDate) " & _
         "VALUES ('" & currentUser() & "', " & _
         "'name of hyperlink clicked', #" & _
         Now & "#)"
DoCmd.RunSql "strsql"

End sub
 
Hit submit too fast....
Code:
Private sub label1_click()
Dim strsql as string

strsql = "INSERT INTO TableName (UserName, [HyperLink field], UpdateDate) " & _
         "VALUES ('" & currentUser() & "', " & _
         "'name of hyperlink clicked', #" & _
         Now & "#)"
DoCmd.RunSql strsql

End sub
 
One last thing, if you don't like warnings, do the following before

Docmd.SetWarnings = False

and at the end

DoCmd.SetWarnings = True
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top