Search Form in Web Database

dkeeper09

Registered User.
Local time
Today, 15:06
Joined
Apr 2, 2013
Messages
10
Hey everyone,

I tried to find an answer to this, but couldn't find anything that works.

I am creating a database in Access 2010. It is a web database and will be uploaded/used on our Sharepoint site.

I have created a search form, called ContactSearch. It has multiple fields, but the first field, for an example, is FirstName. It then searches the query called ContactSearchQ to display the record.

In the criteria field for the query I have:
Like "*" & [Forms]![ContactSearch]![FirstName] & "*"

It works fine...except when it comes to using it on the web database. I am sure there is a solution for creating a search form on a web database, but I have not found it yet.

Any help is greatly appreciated. Thank you.
 
You won't be able to use form references like that in a web database. You'll need to use a macro (maybe two), along with TempVars or SetReturnVars, etc. If you post back with more details, or if you can upload a sanitized copy of your app, I can provide more specific help.
 
Ok, I attached it.


What you said would be brand new to me, so any more help you can give would be great.

Thank you
 

Attachments

I got your db, but I'm running out of time for today so it will be tomorrow before I can look at it and post back with advice.
 
Not a problem at all. You're the one offering your help, so no worries.
 
I do find that this is a limitation to sharepoint. If you are using a web site using a scripted language then this is possible:

Code:
Function Web_ArtistsOriginals()
    
    With CodeContextObject
        Dim WebLink As String
        WebLink = GetWebPathMaster & "Artists_Originals.aspx?Artist=" & .[Artist] & ""
        Application.FollowHyperlink WebLink, , True
        HideWebToolBar
    End With
End Function

Simon
 
OK, so I can't really test anything in your sample application because the tables are still Sharepoint links that I don't have access to. I was able to gather the fields that are in each table just by looking at the queries, etc. but that's about it. If you do regular development updates on this application, you might want to keep a separate test copy with local web tables that are structurally the same as your Sharepoint lists with some dummy data. That way you can test things without worrying about any potential effects on the real app, plus you could post it for help when needed and the person helping you would have access to the tables.

Having said that, I am uploading a different sample db that I put together. You should be able to duplicate this functionality in your app. This sample has one web table, one web query and two web forms (a search form and a results form).

The web query (qrySearch) uses parameters for the values that come from the form. The parameters are called in the criteria of the query, but they also need to be defined in the Parameters section of the query. To define the parameters you just need to provide a name and data type. See the illustrations below for an example.

attachment.php



attachment.php



Moving on to the forms, we have the search form (frmSearch) and the results form (frmResults). The search form is unbound, with five unbound text boxes and two command buttons. The results form is bound to the query. The command buttons on the search form each have an embedded macro in the Click event. The macro for the "Search" button opens frmResults and provides the values for the parameters. Since frmResults is based on a query with defined parameters, then when we call frmResults using the OpenForm or BrowseTo method in a macro, we automatically get prompts for the parameter values. This is where we place the reference to the form controls that the values come from.

Since I mentioned both the OpenForm and BrowseTo methods above, this is a good time to point out the difference. The OpenForm method will open the form in a separate pop up window, with the calling form in the background. This is normal and controllable behavior when running in the Access client (within Access itself), because you can just close the pop up form when you're done with it and you are back to the original form. However, when using the OpenForm method when a web form is running in a browser window, this is not necessarily the behavior we want. Using the OpenForm method in this scenario will cause the called form to open in a new, separate, browser window. This can be problematic because you can't really control what happens when the new browser window is closed (i.e. you can't really be sure where it will return to). Plus, this can end up with a multitude of open browser windows, which can be confusing for the user. This is where the BrowseTo method comes in. This method was created for operating in a browser (which is the general intent of web forms to begin with). When using the BrowseTo method, the new form will open in the same browser window and you can then just use the browsers back button to return to the original form. This is more along the lines of the behavior we expect to see in a web environment. However, when using the BrowseTo method inside the Access client, then we might get behavior that we don't normally expect. The original form is just closed and then the new form is opened. So now, to go back to the original form we have to re-open it. So you have to choose which behavior you would prefer, but since web forms are designed to be run in a browser, then the BrowseTo method would be the one we would normally want to use. That is the method I chose to use in the example, but you can change to the OpenForm method if you don't like the behavior.

Anyway, here is a screenshot of the embedded macro in the Click event of the "Search button on frmSearch;

attachment.php



Then we have the macro in the Click event of the "Clear" button, which just sets the values of the unbound text boxes back to nothing;

attachment.php


Check out the sample db and post back if you have questions.
 

Attachments

  • WebQuery.png
    WebQuery.png
    51.2 KB · Views: 3,336
  • Parameters.PNG
    Parameters.PNG
    26.7 KB · Views: 2,833
  • SearchMacro.PNG
    SearchMacro.PNG
    36.3 KB · Views: 2,962
  • ClearMacro.PNG
    ClearMacro.PNG
    39.8 KB · Views: 2,822
  • WebTest.zip
    WebTest.zip
    33.7 KB · Views: 434
You are awesome. I will check this out as soon as I can. Thank you very much.
 
Hey Beetle,

Thanks for all that.

So, maybe I did something or changed something, but it doesn't pull up any records. Does each field have to be filled out in order for it to find the records?
 
Last edited:
In the test copy that I uploaded, if you click Search without entering criteria in any of the text boxes it will return all records. Otherwise, you can enter criteria in any or all of the text boxes (they do not all have to have entries), and it will return the matching records (or no records if none match the criteria entered).

I have tested this with a Sharepoint back end running in a browser, as well as in the Access client itself, and it works in both environments. If you're unable to get it to work then see if you can create a small, separate Access web db with just a couple of local tables (whichever tables are relevant to the problem) with the same names and structure as your Sharepoint lists, enter a little bit of dummy data, then import the relevant queries/forms from your existing app. If you can duplicate the problem then you can post it here and I can see what's going on.
 
Ok, check out the attached database. Its the exact replica of what I am using I just took out all the data of course and put some test records in there.

The frmPolicySearch and frmContactSearch is where the problem is. They both use ContactSearchQ and PolicySearchQ for the querys and those use the tables Policy and Contacts.

Right now they aren't showing any results for me. I tried to take what you did and copy it into these, but I'm sure there is something missing.

Let me know what you think. Thanks Beetle.
 

Attachments

I am uploading a modified copy of your app.

Your problem here boils down to lookup fields. Now, normally, a lookup field in a table is something that you should avoid for several reasons. However, when it comes to an Access 2010 web database, lookup fields are the only way to create a "relationship" between two tables. Basically, you're being forced into poor practice by the big brains at MS. So you need to be cognizant of this fact and understand how to properly deal with them. A lookup field (in most cases) does not store what it appears to store. It might display a name, but it actually stores the ID value from the related table where it "looks up" the name. So trying to do a search for "Bill Johnson" against this field will fail because it actually stores Bill Johnson's numeric ID value.

There are a couple of ways you can work around this. In your case, where you want to do free form entry in a search form, then you want to actually return the text value you're searching for from the related table. To do this you want to add the other table to the query that your results form is based on, create a relationship and then return the field(s) that contain the actual values that you're searching for. In the case of your ContactSearch query, this means adding the Agents table and creating a relationship between [Servicing Agent] in the Contacts table and [Agent ID] from the Agents table (remember here that [Servicing Agent] is a lookup field that actually stores [Agent ID]). You can then return a concatenated First and Last name as the query field to be used in the search. The nature of the relationship is important here as well. In this case you want a left join (right click on the relationship line in the QBE and go to Join Properties - this is option 2). The reason for this is because you want to return records from the Contacts table even if there are no related record in the Agents table.

In the case of your PolicySearch query, you already had both of the necessary tables in the query, but you had the relationship established on the wrong fields. Again, you were mislead by the lookup field here. The [Contact Name] field in the Policies table stores the ID field from Contacts, not the [Full Name] (which is itself a calculated field - also bad. A lookup (Contact Name) of a calculated field (Full Name) - double your badness for the same price). Anyway, I modified this query as well, which you can see in the example. The left join applies here as well.

I mentioned that calculated fields in A2010 are also bad. You can read a bit more about that here if you want. Scroll down towards the bottom of the page where it talks about calculated fields in A2010. I would also recommend that you avoid spaces or special characters in your field names, as it causes additional work because you often have to bracket them in queries, macros or code.
 

Attachments

Wow. Thanks Beetle. I'll definitely look into all this. This is more help than I thought I would be getting. Thanks again. I'll test this out a little later today and see how it goes.
 
Alright Beetle. Things are working great. The problem now is the result forms are only showing one record. So if I left all the fields blank in the search form, it should show all records, right? They both only show one record
 
Are you sure? In your last test db I noticed that one of your results forms was designed as a standard form, not a continuous (aka multiple items) form. Not sure why it was designed this way, but you had to use the navigation buttons to page through to see the additional records. What does it say in the record navigation area for Record X of Y?
 
Ah. It says 1 of 354. I got it now. I didn't realize it wasnt a multiple form. Thanks for everything Beetle. I think we are finally done here lol.
 
Hi,

It seems that I have the exact same issue that was posted on this thread.
I have tried to follow the instructions as provided, but in my Access application, I am unable to enter any Parameters in the Search Macro builder.
the hyperlink named "update parameters" does nothing when clicked, and I'm assuming this is what should allow you to enter/update the parameter names.

Beetle, if you read this. Do you know if this is normal behaviour, or how I can get to amend/enter the parameters that relate to my database?
Many thanks
 
I used the instructions above to create a search form. My problem is that the search query does not return records, where one of the fields is empty/Null. I checked that the problem also exists in your "Database Test". Only policies with information in all fields are returned in the search result.
Can I modify the search query in a way that it will also return records with empty fields?
 

Users who are viewing this thread

Back
Top Bottom