Change value of single textbox in a recordset - ms-access

First off I apologize for not knowing a lot about Microsoft Access forms. I have had very little involvement with them and this is only to support a legacy product that will soon be replaced.
I have a Microsoft Access form that has a detail section such as the image below (shown in Design View).
I believe the first 6 textboxes are bound to a data set, the last one is bound to nothing (I added it for what I'm trying to do). When I view the form in Form View I see many results (which come from the bound table). The only textbox that does not have info in it is the last one to the right (Unbound).
My goal is to just simply change the value and back color of the following textbox in red.
I want to edit the contents (change "jk" to "Error") and I want to change the background of that one textbox to RED (vbRed). The problem is when I try to change the backcolor it changes all the textboxes called "Errors" (that entire column).
ErrorHandler:
Forms![MyForm1]![Errors].BackColor = vbRed
If I want to get the value of the currently selected cell I can just do the following and it works fine...
MsgBox "Debug: " & Forms![MyForm1]![Code] 'The first column
MsgBox "Debug: " & Forms![MyForm1]![Name] 'The second column
MsgBox "Debug: " & Forms![MyForm1]![Number] 'The third column
MsgBox "Debug: " & Forms![MyForm1]![Errors] 'The Unbound (last column)

To edit and save individual records, the textbox must be bound to a field of the table.
So, add a field of Short Text to the table to hold your error message.

Related

Referencing the value of a hyperlinked text box

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.

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

Access 2007 textbox is seen as empty while it is not

I was searching for my question for hours and I have found some ideas but it still doesn't do what I want.
I have a form "AddWorker" with texboxes "Name", "Surname" and so on.
At the end of this form I decided to use a button to handle addition to database by VBA code.
When I put some data into texboxes I can refer to them by textbox.text property, but only if I am focused on this texbox. In other cases I can use textbox.value property.
In my case when I put all data into 3 textboxes I clik button "Add worker" to add person to database, but last textbox (for example 3) is seen as empty because it did't see text I have put into textbox. I need to clik into another textbox (for example 2 or 1) to create "some event" and then it update textbox 3 and all data can be read in vBA.
What can I do to see all texboxes filled in VBA when i click "Add worker" button.
I have found some example but it didn't help me a lot. I still see empty textbox while clicking "Add worker" button.
Textbox null problem
First of all, make sure the form is unbound. It should not have a recordsource associated with it.
Then, try adding a few messageboxes in the code behind the Add Worker button. Something like:
Sub Add_Worker_Click()
msgbox "Text1: " & Me.TextBox1.Value
msgbox "Text2: " & Me.TextBox2.Value
msgbox "Text3: " & Me.TextBox3.Value
/* Comment out all of your code for now */
End Sub
Give that a shot and see what is in the textboxes. Then replace ".Value" with ".Text" and see what you get.

Display Issue for filtering a combobox in a continuous form

I have a continuous form containing many records. Each record contains a combo box that has vba code filtering the viewable selections when it gains focus (it does this by changing the RowSource.
My problem is that if i click the combo box in record A and then click the combo box is record B, the display-filter for record B is applied to record A. I do not have this problem if I click another control in between clicking the combo boxes.
Why is the filter applied to A's combo box even though focus has (supposedly) been lost? And how do I prevent this display error from happening? The only solution I have now is to make an arbitrary control gain focus when focus for the combobox is lost, but obviously that can be annoying for the user...
Possibly relevant code (SuperintendentID is the name of my combobox):
Private Sub SuperintendentID_GotFocus()
'Filters SuperintendentID based on the task's division
Me!SuperintendentID.RowSource = "SELECT tblJoinDivisionSuperintendent.SuperintendentID, [FirstName] & "" "" & [LastName] AS Name, tblJoinDivisionSuperintendent.DivisionID FROM tblSuperintendent RIGHT JOIN (tblDivision RIGHT JOIN tblJoinDivisionSuperintendent ON tblDivision.ID = tblJoinDivisionSuperintendent.DivisionID) ON tblSuperintendent.ID = tblJoinDivisionSuperintendent.SuperintendentID WHERE tblJoinDivisionSuperintendent.DivisionID = " & Me!DivisionID & ";"
Me!SuperintendentID = Me!SuperintendentID.ItemData(0)
Me!SuperintendentID = Me!SuperintendentID.OldValue 'Prevents a new value from being assigned when the control first gains focus
End Sub
You might be firing both the GotFocus events for comboboxA and comboboxB, but the screen is only showing you the last value you changed.
You could add use a Form.Repaint method (where Form=your form object) as part of the GotFocus event to ensure that the screen was refreshed after changing the underlying datasource.
You could test this to make sure both events are firing by putting a debug.print statement in the event as well, such as debug.print "GotFocus ComboboxA"

combobox cascade effect not working for different rows

I have two comboboxes on a subform.The first combobox is used to populate the second combobox. These are placed in the detail section of the form. I want them to work this way:when I select any value from the first combobox, I want the second combobox of the same row to get populated by relevant value.
As of now, I have tried to implement this and as I select any value from the first combobox of row 1 I see the second combobox of the same row gets populated but as I go on selecting values from the first set of comboboxes I see that the values in the second set of the comboboxes above changing or becoming null.
Here's the code:
The 1st combobox is cboRCMTask:
Private Sub cboRCMTask_AfterUpdate()
Me.cboRCMTaskOptions.RowSource = "SELECT ID, RCMTaskOptions FROM tblRCMTaskOptions WHERE RCM_ID=" & Me.cboRCMTask.Column(0) & ";"
Me.cboRCMTaskOptions = Me.cboRCMTaskOptions.ItemData(0)
Me.cboRCMTaskOptions.Requery
End Sub
cboRCMTaskOptions is the second combobox.
The form_current event:
Private Sub Form_Current()
Me.cboRCMTask.RowSource = "SELECT ID, RCMTask FROM tblRCMTask;"
If IsNull(txtRCM_ID) Then
Me.cboRCMTask = Me.cboRCMTask.ItemData(0)
End If
Me.cboRCMTaskOptions.RowSource = "SELECT ID, RCMTaskOptions FROM tblRCMTaskOptions WHERE RCM_ID=" & Me.cboRCMTask.Column(0) & ";"
If IsNull(txtRCMOption_ID) Then
Me.cboRCMTaskOptions = Me.cboRCMTaskOptions.ItemData(0)
End If
End Sub
From your description, you are using a continuous form. While it looks like a continuous form has many rows, from the point of view of coding you can consider it to have just one row, the current row. I suspect that the control source for combo 2 is a hidden, numeric column in the combo, when you change the row source for the combo, the visible row can no longer be found, so it cannot be displayed. You will either have to provide a pop-up form for editing, or a textbox to store the value for the form and a slightly dodgy combo to edit that value. You can do a little to improve the appearance with conditional formatting.
in your first piece of code, shift the code to the on_click event. I am not sure what you are trying to achieve with the reference to ItemData but I think it is unnecessary, comment out that line.
Similarly the third to last line in the Form_current event, replace with a requery.