Fire update event on keyup - ms-access

I have textbox ("D_find" in its id) on my form witch i use to filter form's data using LIKE query.
I have following code:
Private Sub D_find_AfterUpdate()
Dim fil
fil = Me.D_find
If fil = Null Then
fil = ""
End If
Me.Filter = "DeloN Like '" + fil + "*'"
End Sub
It's working correctly if i press tab or focus some other control on form, but i need to apply filter immediatly after keyup event of the textbox, but i cant to it, because if i use this code in D_find_keyup i always have D_find is NULL, but in current scenario it's always is not null except if it's empty.
The second trouble present in current scenario: after AfterUpdate fired and filter is applied, text color in D_find textbox is going to be white and it rollbacks to black after i type somethin in this textbox (D_find) or cut some text.
--
I'm sorry for my bad English.

If the textbox still has focus, you can use:
NameOfControl.Text
This will contain the text just entered. However, why must you apply the filter immediately, it would be safer in Afterupdate, because you would be sure that all data was entered, and you can set focus back to the search control.
EDIT re Comments
Using a textbox, txtSearch, and a listbox, lstCompanies the following code illustrates the above:
Private Sub txtSearch_Change()
s = "SELECT Key, Company " _
& "FROM tblCompanies " _
& "WHERE Company LIKE '*" _
& Replace(Me.txtSearch.Text, "'", "''") & "*'"
Me.lstCompanies.RowSource = s
End Sub
The listbox returns a gradually diminishing list as letters are added to txtSearch.

Related

populate text box on one form based on combo box selection on another form

I've been looking around and can't seem to find an accurate answer to at least steer me in the right direction. On form1 (Members) i have a button that opens another form (supervisor) with a combo. The combo has 3 fields and upon selection I want it to store the 3 values in a text box on form1 then close form 2 (which I know this code).
Before closing the Form, Use the Vba code as below
Forms![MEMBER].Textbox1= Me.Combobox1 ' set the value of combobox to your Textbox in Form1
Docmd.close 'Close the form
To set the value on form1, use the Column property of Combobox with index value,
Forms!form1!Textbox1 = Me.Combobox1.Column(0) & " " & Me.Combobox1.Column(1) & " " & Me.Combobox1.Column(2)
nevermind I was able to figure it out once my brain started working...
Dim supervisor1 As Variant
Dim supervisor2 As Variant
Dim supervisor3 As Variant
Dim supervisor4 As Variant
supervisor1 = Me.Combo0.Column(0)
supervisor2 = Me.Combo0.Column(1)
supervisor3 = Me.Combo0.Column(2)
supervisor4 = supervisor1 & " " & supervisor3 & " " & supervisor2
Forms![Member].Text48 = supervisor4

Hyperlink text disappears based on combo box value on continuous form

I'm having a bit of an unusual problem (or at least I think it's unusual). I have a continuous form that shows certain records based on a query that updates after I change the value in a combo box. I have a "View All" hyperlinked text box so that I can switch to seeing all of the records when I want to, but have discovered it only appears when I have selected a combo box value that has records. For example, if I want to find records assigned to Joe Shmo and there is one record assigned to him, the hyperlink appears. If I want to find records assigned to Susie Seashell and she has none assigned to her, it disappears. The catch is that if I click on the area of the screen where the hyperlink should appear, it still works as expected-- there is just nothing visible that would lead you to click there. The text field's visibility is on, and I even tried coding in a txtfield.visible=true and it did nothing. Any help would be appreciated!
Note: The hyperlink control source is ="View All". Not sure if that matters or not.
All of the VBA code used on this form is below:
Option Compare Database
Private Sub cboFindNotice_AfterUpdate()
getSearchResults
End Sub
Private Function getSearchResults()
Dim sql As String
Dim errMsg As String
'== Sets value of string 'sql'
sql = "SELECT tblNotice.ID, tblNotice.noticeSEIFnoticeNumber, tblNotice.noticeJurisdiction, tblNotice.noticeDueDate, tblNotice.noticeTitle, " _
& "tblAnalysts.[analyst_lName] & "", "" & [analyst_fName] AS Expr1, tblNotice.noticeStatus" _
& " FROM tblAnalysts INNER JOIN tblNotice ON tblAnalysts.ID = tblNotice.noticeAnalyst" _
& " WHERE tblNotice.noticeAnalyst LIKE '*" & Me.cboFindNotice & "*'" _
& " ORDER BY tblNotice.noticeDueDate"
'== Displays records based on query
Me.Form.RecordSource = sql
Me.Form.Requery
End Function
Private Sub noticeSEIFnoticeNumber_Click()
DoCmd.OpenForm "frmNoticeDetails"
[Forms]![frmNoticeDetails].Controls("txtControlField").Value = Me.Controls("ID").Value
Call Forms.frmNoticeDetails.txtControlField_AfterUpdate
End Sub
Private Sub txtViewAll_Click()
Me.cboFindNotice.Value = ""
Call cboFindNotice_AfterUpdate
End Sub

Microsoft Access - combo box dropdown errors

I am new to VBA/Access so I have been using queries/VBA code I find online to help me build my current form. I experiencing weird behavior with my combo box and i think it may be due to the VBA/queries I have attached to it.
The code below is used to make the combo box a dynamic search tool: as you type each letter, it reruns the query to update the list with only the last names that match the letters typed.
However, pressing the arrow keys/tab/enter does nothing. The only way to navigate/select a value in the dropdown is a mouse click. And when I click the value I want, the form populates the data from the that record (yay!) but the dropdown menu stays visible until i click the background of the form.
I want the dropdown to disappear as soon as I select the record I want, and if possible I want to be able to use the arrow keys to navigate.
The "On Change" event has this code:
Private Sub Combo1397_Change()
Dim strText, strFind
Combo1397.SetFocus
strText = Me.Combo1397.Text
If Len(Trim(strText)) > 0 Then
strFind = "[Last Name] Like '"
For i = 1 To Len(Trim(strText))
If (Right(strFind, 1) = "*") Then
' When adding another character, remove the
' previous "*," otherwise you end up with
' "*g**w*" instead of "*g*w*."
' This has no apparent impact on the user, but
' ensures that the SQL looks as intended.
strFind = Left(strFind, Len(strFind) - 1)
End If
strFind = strFind & "*" & Mid(strText, i, 1) & "*"
Next
strFind = strFind & "'"
strSQL = "SELECT tbl_RC_Main.pk_CandidateID, tbl_RC_Main.[Last Name],tbl_RC_Main.[First Name], tbl_RC_Main.Email FROM tbl_RC_Main Where " & _
strFind & " ORDER BY [Last Name];"
Me.Combo1397.RowSource = strSQL
Else
' Show the entire list.
strSQL = "SELECT tbl_RC_Main.pk_CandidateID, tbl_RC_Main.[Last Name],tbl_RC_Main.[First Name], tbl_RC_Main.Email FROM tbl_RC_Main ORDER BY tbl_RC_Main.[Last Name]; "
Me.Combo1397.RowSource = strSQL
End If
Me.Combo1397.Dropdown
End Sub
Also,
On the "After Update" event I have a "Search for Record" macro
Because you have Me.Combo1397.Dropdown in the Change event, the combobox will drop down again upon selecting a value. You should instead move Me.Combo1397.Dropdown to the Enter event.
If you also remove Combo1397.SetFocus (I can't see why it's needed) then you will be able to use the Enter/Tab/Arrow keys as well.

Passing query result to a textbox control on an access form

I need help with a textbox field on an Access 2007 form. I'm trying to insert the result of a query into the text box control on the form. This is used soley as information for the user. The form supplies the query with parameters to get the value. The query works fine and returns the correct result. What I can't seem to figure out is how to pass the query result to the textbox. I’ve tried several different ways but with no luck.
(PS> I know a combo box can do a lookup, however I don’t want the user to have to click the dropdown just to select the value as there can only ever be one value result from the query.) I'm open to suggestions as I'm not a programmer or DB Admin, but I've taking a few classes on Access (enough to be dangerous).
Private Sub cbo3_Change()
Me.tbx2 = ("SELECT tbl_Billing.Savings_b FROM tbl_Billing GROUP BY tbl_Billing.UBI_b, tbl_Billing.TaxYr_b, tbl_Billing.TaxPrg_b, tbl_Billing.Savings_b HAVING (((tbl_Billing.UBI_b)=forms!f1_UpBilled!cbo1) And ((tbl_Billing.TaxYr_b)=forms!f1_Upbilled!cbo2) And ((tbl_Billing.TaxPrg_b)=forms!f1_UpBilled!cbo3));")
End Sub
If you wish to do this in run time, you need to do the following, I take the controls you are referring to in this is on the same form.
The very simple and straight forward way to get it done is as follows,
Private Sub cbo3_Change()
Dim tmpRS As DAO.Recordset
Set tmpRS = CurrentDb.OpenRecordset("SELECT tbl_Billing.Savings_b FROM tbl_Billing GROUP BY " & _
"tbl_Billing.UBI_b, tbl_Billing.TaxYr_b, tbl_Billing.TaxPrg_b, " & _
"tbl_Billing.Savings_b HAVING ((tbl_Billing.UBI_b = '" & Me.cbo1 & "') And (tbl_Billing.TaxYr_b = '" & Me.cbo2 & "') " & _
"And (tbl_Billing.TaxPrg_b = '" & Me.cbo3 & "'))")
If tmpRS.RecordCount > 0 Then
Me.tbx2 = tmpRS.Fields(0)
Else
Me.tbx2 = 0
End If
Set tmpRS = Nothing
End Sub
Just note, I have implied all your combo boxes are returning String and the field you are comparing against are Text type. If that is not the case, you need to make changes accordingly.

filter continuous form using textbox

I need to let users filter a continuous form using values the user enters into a textbox. And the continuous form is also nested within a couple levels of navigation subforms. This sounds easy enough, but all the examples I find on the web use macros instead of vba.
I set up the structure and wrote an AfterUpdate procedure for a textbox txtFilter as follows:
Private Sub txtFilter_AfterUpdate()
Dim filterval As String
filterval = txtFilter.Value
With Forms!Main!NavigationSubform.Form!NavigationSubform.Form
.Filter = "LastName Like " & filterval
.FilterOn = True
End With
End Sub
I have played with different syntax, but none of it seems to work properly. Here is a link to download the relevant parts of the database from a file sharing site: http://jmp.sh/v/HGctZ4Ru74vDAjzN43Wq
Can anyone show me how to alter this so that users can use the textbox to filter the continuous form?
I got it to work using this: .Filter = "LastName Like """ & filterval & """"
Need those annoying String Identifiers even for strings sometimes.
Okay, To get the form to open with no records and then pull up just the records you (or the user) specifies is easiest with a bit of re-work.
(I'd recommend you working with a copy and not your original)
1:On your Continuous Form, remove the Recordsource; we're going to use Late Binding (Kinda)
2:Then delete the code under the txtFilter box, then delete the box itself.
3:Add a comboBox with something like this as the recordsource:
SELECT DISTINCT myTable.LastName FROM myTable ORDER BY myTable.LastName; (This will get you a unique list of last names so knowing how to spell the name will not be necessary, plus it assures at least one match)
4:In the After Update event of that combobox, add code like this:
Dim strSource As String
strSource = "SELECT mt.IntakeNumber, mt.ClientNumber, " & _
"mt.LastName, mt.FirstName, mt.ConsultationDate " & _
" FROM myTable mt " & _
"WHERE (mt.LastName)= '" & Me.cboFilter.Value & "'"
Me.RecordSource = strSource
Me.Requery
Obviously you'll need to change the table and field names as necessary, but hopefully you get the idea.
Option Compare Database
Option Explicit '<- always include this!!!!!
Private Sub txtFilter_AfterUpdate()
Dim strFilter As String
' only set Filter when text box contains something
' to search for ==> don't filter Null, empty string,
' or spaces
If Len(Trim(Me.txtFilter.Value & vbNullString)) > 0 Then
strFilter = "LastName Like '*" & _
Replace(Me.txtFilter.Value, "'", "''") & _
"*'"
' that Replace() prevents the procedure from breaking
' when the user enters a name with an apostrophe
' into the text box (O'Malley)
Debug.Print strFilter ' see what we built, Ctrl+g
Me.Filter = strFilter
Me.FilterOn = True
Else
' what should happen here?
' maybe just switch off the filter ...
Me.FilterOn = False
End If
End Sub