Referencing the value of a hyperlinked text box - ms-access

So I'm having some difficulties with this code. I know it's obnoxiously wordy, but every attempt I made to turn some of these form references into variables to save space ended with me having even less functionality than before.
Basically what I've done so far is create a navigation form with several tabs, one to create a ticket, one to resolve/edit a ticket, and one to search the tickets. The search tab is basically a continuous form that updates based on the search criteria I enter. My goal is that when I click on the ticketID for each record, it will take me to the selected record on the Resolve/Edit Ticket page (on that page I have a combo box [called cboGoToRecord] where you can select the record you want).
I have a hyperlink in place that takes the user to the Resolve/Edit page and code that works ONLY when the line I've denoted with four asterisks (for clarity) is replaced with
rst.FindFirst "ticketID =" & [some number].
When I do that, the results are as expected. If I leave it as it is below, every record looks up the first record (A Debug.print check shows that the value of this field is apparently always 1...) So I guess what I need to figure out is how do I access the ticketID hyperlink's value so that I can put it on that line and make my code function effectively? I apologize if this is overly detailed but figured too much was better than not enough.
Private Sub ticketID_Click()
'Takes user from Search Tickets to Resolve/Edit Issues tab
DoCmd.BrowseTo acBrowseToForm, "frmResolveIssues", "frmBrowseTickets.NavigationSubform"
On Error Resume Next
Dim rst As Object
Set rst = Forms!frmBrowseTickets!NavigationSubform.Form.RecordsetClone
[Forms]![frmBrowseTickets]![NavigationSubform].Form![cboGoToRecord].Value = [Forms]![frmBrowseTickets]![NavigationSubform].Form![ticketID].Value
****rst.FindFirst "ticketID =" & [Forms]![frmBrowseTickets]![NavigationSubform].Form![cboGoToRecord].Value
Forms!frmBrowseTickets!NavigationSubform.Form.Bookmark = rst.Bookmark
Debug.Print [Forms]![frmBrowseTickets]![NavigationSubform].Form![ticketID].Value
End Sub
Edit:
After altering my form to add a separate hyperlink and referencing the static ticketID, I have concluded that everything I thought was true was not. Finding the value of a hyperlink was NOT the problem. The problem is that my ticketID value truly does insist on being one, and I have no clue how to fix that.

When this works:
Debug.Print [Forms]![frmBrowseTickets]![NavigationSubform].Form![ticketID].Value
then also check out:
Debug.Print [Forms]![frmBrowseTickets]![NavigationSubform].Form![cboGoToRecord].Value
As June7, I never use the Navigation form. It complicates everything too much.

Related

Opening form from combo box in another form

I have a form called DisplayForm. In that form is a combo box drop down that is at the top of column on the form where a label would usually go. I want to select an item from that drop down menu and use that bit of data to open another form. I have copied an example from the web, changed the names and can't get it to work. Here is the code;
If Not Me.NewRecord Then
DoCmd.OpenForm "AreaForm", _
WhereCondition:="LArea=" & Me.AreaCBDrop
End If
Area is the name of the field in the query that is the recordsource for the form, but when I run it, it opens a msgbox that wants me to enter a peramater value. I also don't understand what the IF is about. I have tried this with and without the if but get the same result. Me.AreaCBDrop has the correct value in it, but the where does not work.
Thanks
Thanks
Your WHERE condition is expecting a text parameter, but you are not supplying the expected format, so it is asking for one.
Surround your Me.AreaCBDrop with single quotes, like this:
If Not Me.NewRecord Then
DoCmd.OpenForm "AreaForm", _
WhereCondition:="LArea='" & Me.AreaCBDrop & "'"
End If

Update Display for Combo Box

I have a form with multiple combo boxes, these boxes have 2 column list where column 0 width is zero. All these boxes have row sources defined for their drop down list values.
When I try to over ride the display value of the combo boxes via vb code, it works for few of the controls while doesnt do anything for the rest. So I made an isolated code just to update values of all combo boxes(cbo) and again the same controls pass/fail. Here is the code I am trying to work with, can anyone please tell me why I am unable to update some combo boxes while others work fine?
Thanks!
Sub test()
Dim Ctrl As Control
Dim CtrlName_Combined as String
For Each Ctrl In Forms("frmNewTransaction").Controls
'Name of all combo boxes start with 'cbo'
If Left(Ctrl.Name, 3) = "cbo" Then
Ctrl = "Hello"
CtrlName_Combined = ctrlName_Combined & Ctrl.Name & " "
End If
Next Ctrl
MsgBox CtrlName_Combined
End Sub
Here is screenshot of the form after code run (All Combo boxes start with cbo):
Thank you guys for the help. The problem started when few of the combo boxes did not take value when i executed:
forms("FormName").Controls("ComboBoxName")="Some Value which was in the list"
So I tested all my combos by passing them value "Hello" which I know was not in their row source. Strangely so few combos responded and others did not. This was the rabbit hole as all my combos were configured same apart from their row source queries but all had an ID and eName column.
Problem was that few combos were not taking the text values I passed them but turns out that if I gave them Numeric value according to the first column they start responding (what i dont get here is that how some combos behave one way and rest the other way)
Anyway this helped me get past the problem, thought i should share this after bothering you all with it.
Also I am seeing that the question or manner was not well received by the community, would be helpful if someone pointed out what not to do for future references
Thanks Again!

How to make Access select the entire text in a box instead of all records when using ctrl+a?

In Access, is there a way to set what is selected when a user hits ctrl+a? I have a text box for users to input data, but if they hit ctrl+a, it selects all of the records instead of the entire text of a field. Is there a way to get around this? I am worried about someone accidentally deleting a bunch of records instead of the text of a field.
I'm a beginner user, so please forgive me if I am asking a silly question. I tried to search the forum, but haven't found a good answer.
Working with a textbox and the Keydown event, you can say:
Private Sub Content_KeyDown(KeyCode As Integer, Shift As Integer)
' Debug.Print KeyCode, Shift
If KeyCode = vbKeyA And Shift = acCtrlMask Then
MsgBox "Please use F2"
KeyCode = 0
Shift = 0
End If
End Sub
The textbox is called Content in this case.
You may like to get more complicated and look into KeyPreview.

Access label controls have different properties listed - how can I resolve this?

I have a problem I believe is related to this problem. I have many label controls. Some of them become "weird" and start exhibiting a weird "extra bold" display:
These labels have the same formatting but obviously have different visual representations.
After looking into the properties for both labels, I noticed something quite strange: they have different properties. The broken label properties section actually is not showing the HyperLink properties nor the on-event actions.
In fact, the "Events" properties sheet is actually empty when I go view it.
I am quite confused what is going on here. I would like a way to fix these controls, preferably using VBA so I can add a programmatic fix to update all the broken labels.
Much to my surprise, the following code works:
Application.Forms(gMananger_FormName).controls("Label13").HyperlinkAddress=""
I was expecting some sort of error since those labels do not show that control.
I have also tried Compact/Repair to no avail. Nor did turning ClearType off in the Access options, as suggested in the link above.
I have also written the following code to copy/add a new control but this breaks completely when controls are in tab spaces (it inserts a new line but doesn't delete the row, perhaps I could fix this if I spend more time, I'm concerned about accidentally deleting a ton of my form controls should I do this).
Sub testCopyingControl()
Dim c
Dim i As Integer, key
Dim prop As Scripting.Dictionary
Set prop = New Scripting.Dictionary
Set c = Application.Forms(gMananger_FormName).Controls("Label3120")
For i = 0 To c.Properties.count - 1
prop.Add c.Properties(i).Name, c.Properties(i).value
Next i
Dim newC As Label
Set newC = CreateControl(gMananger_FormName, acLabel)
DeleteControl gMananger_FormName, c.Name
'there are a fair number of readonly properties unfortunately...
On Error Resume Next
For Each key In prop.Keys
Debug.Print key & vbTab & prop(key)
newC.Properties(key) = prop(key)
Next key
End Sub
I can also fix this individually by cutting/pasting and moving the label back to its grid location. However this is a lot of work as I have quite a few controls doing this.
How can I first fix a single label control exhibiting this behavior?
How can I do this programatically via VBA?

Subform losing focus when Adding new record

My DB is split into Front and Back. I have three tables that I am working with in this problem; tblMain, tblDetail, tblNote. I know that the number of records is relatively small but I am designing this for long term use. I have a bound form (frmMain) for tblMain that has a subform (subDetail) for tblDetail. SubDetail has a subform (subNote) for tblNote. When I click a button on the main form, frmMain, the subDetail form becomes visible and allows me to add a new record. I copied the button and the VBA to subDetail so I could do the same thing for adding a record to subNote if needed. However, after the record is created, the subNote form disappears and focus is returned to subDetail. If I move to a new record then back, the subNote form becomes visible and shows an empty record except for the PK. I've checked all the properties of both subDetail and subNote. They are the exact same except for the OnCurrent event for subDetail. I have the following for the subDetail OnCurrent Event.
'Hide subform if no records
Private Sub Form_Current()
Me!ctrlmlsID.SetFocus
With Me!subNote.Form
.Visible = (.RecordsetClone.RecordCount > 0)
End With
End Sub
This hides or displays the subform, subNote, depending on if there is any records or not. Any help in figuring out this behavior would be appreciated.
Here is the code for adding a new record to subNote upon button click.
If Me.Dirty Then Me.Dirty = False
Dim AddTransID As String
AddTransID = Me!ctrlID.Value
Me!subNote.Visible = True
Me!subNote.SetFocus
DoCmd.GoToRecord , , acNewRec
Me!subNote.Form!ctrlID = AddTransID
Me!subNote.Form!ctrlType.SetFocus
I've used breakpoints and the adding record works just fine. It's just the subform going invisible again and the focus being changed back to the parent that is the issue because it won't allow those notes to be added.
I get the impression you are fighting Access here.
You normally do not need a button to create a new record using a properly bound subform with AllowAdditions = True. That will happen automatically.
The problem you are running into may stem from the fact that the new records don't really exist yet until saved (as you observe there is no PK value). So the logic to hide subforms isn't going to work. If you insist on staying with this approach you might try
.Visible = (.RecordsetClone.RecordCount > 0 or .NewRecord)
But I think your life will be easier if you remove the buttons and code you have mentioned and let Access do what it is good at doing. Make sure your subform data binding properties are set right.