How do I make a search form in Access 365 - ms-access

I am currently trying to make a search form for my database. I want to place it in a navigation form (so I heard I can't use a split form). I currently have a form with 4 text boxes and one combo box for a total of 5 criteria to search with a separate button for each. Underneath, is a query based on my table. This is what I have done so far
I'm hitting a wall on how to actually perform the search though. I have never used access before this project and have no idea how to use VBA (but I do know other languages). Is it possible to perform the search using macros? If not, how would I make a search sub-procedure?

The way you approach this is to build the search form and develop and test the search form. Get it working? You can then drop this working form into an existing “navigation form set”.
There are a gazillion ways to do this – you are quite much only limited by your imagining. However, a common setup is to create a “main” form. This main form can have a few text boxes for you to type in your search values. And then you use the wizards to create a “results” form (a nice form in which you display the results for the user to see + pick the results).
In fact, you really don’t have to use a form + sub form, but I find this often works somewhat better then placing the “criteria” boxes in the forms heading area.
So create main form – this form is unbound (not attached to any table in the system). Have fun, lay out the form anyway you want.
Then use the wizards to create a multiple items form. Get that form laid out with nice columns. Now with main form in design mode, simply drag + drop in the “display results” form.
The result is an access form that looks like this:
In above, note how the user “typed” in some criteria.
So you place some code in the text box “after” update event. It can look like this:
dim strSql as string
strSql = "select * from tblCustomer where LastName like " & me.txtLastName
& "*"
me.MySubFormname.Form.RecordSource = strSql
So we “build” the sql on the fly, and “stuff” the sql right into the sub form to display the results.
Note also in the above contines items form, we have a “view” or “edit” button when clicked can launch a detail form to the ONE record you select. In my example I used a “glasses” icon for the button. The code behind that buttion is thus:
Docmd.OpenForm "frmEditDetails",,,"id = " & me!id
edit: the sql string has to be correct, so in above, it should be:
dim strSql as string
strSql = "select * from tblCustomer where LastName like '" & me.txtLastName & "*'"
debug.print strSql
me.MySubFormname.Form.RecordSource = strSql
So VERY little code is required. The rest is simply whatever your fancy is in terms of how you lay out the UI.

Related

Concatenate Rich Text Fields (HTML) and display result on Access form

I have an access database which deals with "articles" and "items" which are all textual stuff. An article is composed of several items. Each item has a rich text field and I wish to display the textual content of an article by concatenating all rich text fields of its items.
I have written a VBA program which concatenates the items rich text fields and feeds this into an independent TextBox control on my form (Textbox.Text = resulting string) but it does not work, I get an error message saying "this property parameter is too long".
If I try to feed a single textual field into the Textbox control, I get another error stating "Impossible to update the recordset" which I do not understand, what recordset is this about ?
Each item field is typically something like this (I use square brackets instead of "<" and ">" because otherwise the display of the post is not right) [div][font ...]Content[/font] [/div]", with "[em]" tags also included.
In front of my problem, I have a number of questions :
1) How do you feed an HTML string into an independent Textbox control ?
2) Is it OK to concatenate these HTML strings or should I modify tags, for example have only one "[div]" block instead of several in a row (suppress intermediate div tags) ?
3) What control should I use to display the result ?
You might well answer that I might as well use a subform displaying the different items of which an article is made up. Yes, but it is impossible to have a variable height for each item, and the reading of the whole article is very cumbersome
Thank you for any advice you may provide
It works for me with a simple function:
Public Function ConcatHtml()
Dim RS As Recordset
Dim S As String
Set RS = CurrentDb.OpenRecordset("tRichtext")
Do While Not RS.EOF
' Visually separate the records, it works with and without this line
If S <> "" Then S = S & "<br>"
S = S & RS!rText & vbCrLf
RS.MoveNext
Loop
RS.Close
ConcatHtml = S
End Function
and an unbound textbox with control source =ConcatHtml().
In your case you'd have to add the article foreign key as parameter to limit the item records you concatenate.
The "rich text" feature of a textbox is only intended for simple text.
We use the web browser control to display a larger amount of HTML text, and load it like this:
Private Sub Form_Current()
LoadWebPreview
End Sub
Private Sub HtmlKode_AfterUpdate()
LoadWebPreview
End Sub
Private Sub LoadWebPreview()
' Let the browser control finish the rendering of its standard content.
While Me!WebPreview.ReadyState <> acComplete
DoEvents
Wend
' Avoid the pop-up warning about running scripts.
Me!WebPreview.Silent = True
' Show body as it would be displayed in Outlook.
Me!WebPreview.Document.body.innerHTML = Me!HtmlBody.Value
End Sub

MS Access add a search form

In Access I have some difficulties to create a search form based on a Query. The search form will be based on the title
Steps:
1. On my query field I add this formula
[Forms]![Main Menu]![SearchInput]
I added a InputBox (SearchInput) and a Button in the Main Menu form.
I connected the Button to the Query.
Result
When I type A in the SearchInput box suppose to render all the Title that contains a A but it returns nothing.
I had to put this into the Criteria of the Query
Like "*" & [Forms]![Main Menu]![SearchInput] & "*"

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

cascading combo box causing empty fields in next record

I'm having problems with a cascading combo box. Everything works fine with the combo boxes and the values get populated correctly.
Private Sub cmbAdjComp_AfterUpdate()
Me.cboAdjOff.RowSource = "SELECT AdjusterCompanyOffice.ID,
AdjusterCompanyOffice.Address1,
AdjusterCompanyOffice.Address2,
AdjusterCompanyOffice.Address3,
AdjusterCompanyOffice.Address4,
AdjusterCompanyOffice.Address5 FROM" & _
" AdjusterCompanyOffice WHERE
AdjusterCompanyOffice.AdjCompID = " & Me.cmbAdjComp.Column(1) & _
" ORDER BY AdjusterCompanyOffice.Address1"
Me.cboAdjOff = Me.cboAdjOff.ItemData(0)
End Sub
The secondary combo box has a row source query:
SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1,
AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3,
AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM
AdjusterCompanyOffice ORDER BY AdjusterCompanyOffice.Address1;
Both comboboxes have the same controlsource.
Everything works fine and dandy moving between records and the boxes show the correct fields for each record.
When i use the first combo box, and then select the appropriate option in the second combo box, everything works great on the specific record.
However when I move to the next record, the values in the second combo box are all empty. If i close the form and reopen it, and avoid using the cascading combo boxes all the values are all correct when i move between records.
Somehow using the cascading combo boxes creates a conflict with the row source of the secondary combo box.
Hope that is clear! Have been rummaging around for an answer but cant find anything.
any help would be greatly appreciated.
Thanks
Noel
The reason why the combo box is blank when you navigate to the next record is because you have NotInList set to TRUE (which is what you want), but when you arrive on the record, the rowsource has been filtered to not include the value stored in the field the combo box is bound to. Thus, it's blank -- the value is there, but it can't be displayed, since it's not in the list.
To fix this, you need to clear the filter on the second combo box. To do that, in the OnCurrent event of your form, set the rowsource of the filtered combo box to be unfiltered:
Me!cboAdjOff.RowSource = "SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1, AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3, AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM AdjusterCompanyOffice ORDER BY AdjusterCompanyOffice.Address1"
I usually handle this by creating two constants at the top of the form's module, one for the SELECT statement and one for the ORDER BY:
cstrRecordsourceSelect = "SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1, AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3, AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM AdjusterCompanyOffice"
cstrRecordsourceOrderBy = "ORDER BY AdjusterCompanyOffice.Address1"
Then it's much easier to handle. In the OnCurrent it looks like this:
Me!cboAdjOff.RowSource = cstrRecordsourceSelect & " " & cstrRecordsourceSelect
...and in the AfterUpdate of your first combo box:
Me!cboAdjOff.RowSource = cstrRecordsourceSelect & _
"WHERE AdjusterCompanyOffice.AdjCompID = " & Me!cmbAdjComp.Column(1) & _
" " & cstrRecordsourceSelect
This makes the code easier to read, and it also makes it easier to alter the rowsource if you need to, since you have to edit only the constant.