I have form that looks a lot like a search bar for the user to search
for records matching specified criteria (e.g. first names containing
"ben"). For robust results, an intermediary form displays all records
matching the criteria (hmm...sound like a popular web site I know).
Here is the immediate problem: my code (below) works fine on my
computer, but on some of those belonging to my work colleagues (who
will be the end users of the db) it does not seem to work. This is
particularly hard to debug because I have to use other PC's to
duplicate the error. Other controls with similar event code DO work.
The only difference between working controls/event code and nonworking
ones seems to be in the "whencondit ion" of the DoCmd.OpenForm. Do I
need to add something to the code so that it will work on all PC's?
(Aside: Security is not enable so all users should be "Admin"; the
problem would appear to be related to the PC, not the user.) HELP
PLEASE!
**********code that works********** **
Private Sub cmdEdit_Click()
DoCmd.OpenForm FormName:="frm_ Search", view:=acNormal
Forms![frm_Search].Tag = 1
Forms![frm_Search].txtSubject = ""
End Sub
**********code that doesn't always work*********** ***
Private Sub cmdSearch_Click ()
Dim category As String
Dim subject As Variant
subject = Forms!frm_Searc h!txtSubject.Te xt
category = Forms!frm_Searc h!cmbCategory.T ext
DoCmd.OpenForm FormName:="frm_ Browse", view:=acNormal,
wherecondition: = category & " Like " & Chr$(34) & "*" & subject &
"*" &
Chr$(34)
End Sub 6 1881
benb wrote: I have form that looks a lot like a search bar for the user to search for records matching specified criteria (e.g. first names containing "ben"). For robust results, an intermediary form displays all records matching the criteria (hmm...sound like a popular web site I know). Here is the immediate problem: my code (below) works fine on my computer, but on some of those belonging to my work colleagues (who will be the end users of the db) it does not seem to work. This is particularly hard to debug because I have to use other PC's to duplicate the error. Other controls with similar event code DO work. The only difference between working controls/event code and nonworking ones seems to be in the "whencondit ion" of the DoCmd.OpenForm. Do I need to add something to the code so that it will work on all PC's? (Aside: Security is not enable so all users should be "Admin"; the problem would appear to be related to the PC, not the user.) HELP PLEASE!
**********code that works********** ** Private Sub cmdEdit_Click() DoCmd.OpenForm FormName:="frm_ Search", view:=acNormal Forms![frm_Search].Tag = 1 Forms![frm_Search].txtSubject = "" End Sub
**********code that doesn't always work*********** *** Private Sub cmdSearch_Click () Dim category As String Dim subject As Variant
subject = Forms!frm_Searc h!txtSubject.Te xt category = Forms!frm_Searc h!cmbCategory.T ext DoCmd.OpenForm FormName:="frm_ Browse", view:=acNormal, wherecondition: = category & " Like " & Chr$(34) & "*" & subject & "*" & Chr$(34)
End Sub
Here's something to try as a first step:
Does it only work when cmbCategory.Val ue matches the name of a field
contained in the RowSource of the form? Your wherecondition should
probably start with the literal name of the field you are searching on.
Something like:
wherecondition := "Category Like " & Chr(34) & "*" & cmbCategory.Val ue
& "*" & Chr(34)
or
wherecondition := "Subject Like " & Chr(34) & "*" & txtSubject.Valu e &
"*" & Chr(34)
or
wherecondition := "(Category Like " & Chr(34) & "*" & cmbCategory.Val ue
& "*" & Chr(34) & ") AND (" & "Subject Like " & Chr(34) & "*" &
txtSubject.Valu e & "*" & Chr(34) & ")"
(Note that Like "**" is equivalent to Like "*") Like "*" doesn't get
Null values so I often do something like:
If Not IsNull(cbxCity. Value) Then
strWhere = strWhere & " AND ([City] LIKE '" & cbxCity.Value & "')"
Else
strWhere = strWhere & " AND (([City] LIKE '*') OR ([City] Is Null))"
End If
when building a SQL string if I want a Null in a search textbox to
return all records. I have seen mysterious situations where the SQL
created with "((MyField Like '*') Or (MyField IS NULL))" for multiple
fields failed to return all the records so the most robust approach
when possible is more like:
If Not IsNull(cbxCity. Value) Then
strWhere = strWhere & " AND ([City] LIKE '" & cbxCity.Value & "')"
End If
so that there are no restrictions of any kind when the value in a
search control is Null. You should be able to do something like:
wherecondition := strWhere
For debugging you can put your strWhere in a SQL WHERE clause to see if
it's returning the correct records.
Hope this helps,
James A. Fortune
Thanks for the tips. The problem, however, isn't with the results of
the wherecondition. There aren't any results because the code just
doesn't execute at all. To answer your question, cmbCategory is a
combo box limited to the names of four field names so that the code
filters the form to show just records where the value in field
cmbCategory.Val ue is like txtSubject.Valu e. I'm hoping that I'll find
some machines just don't have the right libraries enabled, but I doubt
I'll be so lucky. I just don't have many ideas as to why code would
work on some machines and not others.
benb wrote: Thanks for the tips. The problem, however, isn't with the results of the wherecondition. There aren't any results because the code just doesn't execute at all. To answer your question, cmbCategory is a combo box limited to the names of four field names so that the code filters the form to show just records where the value in field cmbCategory.Val ue is like txtSubject.Valu e. I'm hoping that I'll find some machines just don't have the right libraries enabled, but I doubt I'll be so lucky. I just don't have many ideas as to why code would work on some machines and not others.
I see what you're doing now. I've never seen anyone do it quite like
that but that's O.K. A missing reference would cause code not to run
but it would give some kind of error message. Concentrate on what's
needed to get it working since you have a show-stopper. If that
doesn't work, then For different machines acting differently I would,
as a start, check for missing references, different OS's, different
SP's, different versions of Access, different versions of Jet,
different versions of other DLL's. Try the /decompile switch and
reload a fresh copy of the app. Uninstall AOL 6.0 :-).
James A. Fortune
I got it working. It was an issue with the references. But now you
have my curiousity. Is there a better way of doing this? With regard
to the .Value vs. .Text, I used .Text because the combo box would
return the index value (1, 2, 3, etc.) rather than the text value.
Anyway, thanks for your help!
Just to pick your brain a bit, I'm trying to come up with some code to
add to this that will count the number of records matching the criteria
(e.g. records of contact with the first name "Jim"). If there is only
one, I want to circumvent the intermediary form that displays the
search results and just go straight to the full record. Does that make
sense? I know there has to be a way of doing this, but I don't know
how easy/difficult it may be.
benb wrote: I got it working. It was an issue with the references. But now you have my curiousity. Is there a better way of doing this? With regard to the .Value vs. .Text, I used .Text because the combo box would return the index value (1, 2, 3, etc.) rather than the text value. Anyway, thanks for your help!
I'm glad I was able to help point you toward a solution. Value works
fine even when index values are returned. Google this NG to find out
the subtle difference between .Value and .Text.
Just to pick your brain a bit, I'm trying to come up with some code to add to this that will count the number of records matching the criteria (e.g. records of contact with the first name "Jim"). If there is only one, I want to circumvent the intermediary form that displays the search results and just go straight to the full record. Does that make sense? I know there has to be a way of doing this, but I don't know how easy/difficult it may be.
Bringing up only the full record when there is only one match is an
excellent idea. I think I'll implement that into some of my search
forms tonight. Thanks for the idea. I've used that idea many times
before but not with search forms. I was just being lazy I guess. My
unbound search form generates ad hoc SQL that can be used to count the
number of results. If the RecordCount is one, I can skip the
SearchResults form and go directly to the Info form. Post back if you
have any difficulties.
James A. Fortune
Do you do anything besides play pool? -- Tom
benb wrote: Just to pick your brain a bit, I'm trying to come up with some code to add to this that will count the number of records matching the criteria (e.g. records of contact with the first name "Jim"). If there is only one, I want to circumvent the intermediary form that displays the search results and just go straight to the full record. Does that make sense? I know there has to be a way of doing this, but I don't know how easy/difficult it may be.
This turned out to be pretty simple.
On the Form_Load event of frmSearchResult s I now have something like:
Me.RecordSource = GetSearchSQL()
If Me.RecordsetClo ne.RecordCount = 1 Then
Call cmdSelect_Click
End If
James A. Fortune This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: James Cameron |
last post by:
Hi I'm developing a program and the client is worried about future
reuse of the code. Say 5, 10, 15 years down the road. This will be a
major factor in selecting the development language. Any comments on
past experience, research articles, comments on the matter would be
much appreciated. I suspect something like C would be the best based
on comments I received from the VB news group.
Thanks for the help in advance
James Cameron
|
by: Cardman |
last post by:
Greetings,
I am trying to solve a problem that has been inflicting my self
created Order Forms for a long time, where the problem is that as I
cannot reproduce this error myself, then it is difficult to know what
is going on.
One of these Order Forms you can see here...
http://www.cardman.co.uk/orderform.php3
|
by: Steven T. Hatton |
last post by:
This is a purely *hypothetical* question. That means, it's /pretend/,
CP. ;-)
If you were forced at gunpoint to put all your code in classes, rather than
in namespace scope (obviously classes themselves are an exception to this),
and 'bootstrap' your program by instantiating a single application object
in main(), would that place any limitations on what you could accomplish
with your program? Are there any benefits to doing things that...
|
by: joe |
last post by:
Hi I am trying to compile a cpp ap that runs on the system tray and checks
recently open files with clamav. i am getting a whole bunch of undefined
erros. can i link this library to a cpp program? do i need any special
confiure options?. i tried removing pthread and other libraries and the
results are similar. or should i write a small lib that checks buffers
and just use my lib with extern? thanks for the advice.
the code looks like...
|
by: Lues |
last post by:
Hi,
I'm trying to protect some data in tables with encription (you know why,
don't you ;))
I must confess that I'm not very expirienced in writing code, especially
encription code.
Can any one, please , send VB code for access which I can c/p into one
function. It don't have to be RSA, it can be anything which is easy to
| |
by: Vortex Soft |
last post by:
http://www.junglecreatures.com/
Try it and tell me what's happenning in the Microsoft Corporation.
Notes:
VB, C# are CLS compliant
|
by: Cheryl Langdon |
last post by:
Hello everyone,
This is my first attempt at getting help in this manner. Please
forgive me if this is an inappropriate request.
I suddenly find myself in urgent need of instruction on how to
communicate with a MySQL database table on a web server, from inside
of my company's Access-VBA application. I know VBA pretty well but
have never before needed to do this HTTP/XML/MySQL type functions.
|
by: Bayazee |
last post by:
hi
can we hide a python code ?
if i want to write a commercial software can i hide my source code from
users access ?
we can conver it to pyc but this file can decompiled ... so ...!!
do you have any idea about this ...?
---------------------------------------
First Iranian Open Source Community : www.python.ir
|
by: robert maas, see http://tinyurl.com/uh3t |
last post by:
I'm working on examples of programming in several languages, all
(except PHP) running under CGI so that I can show both the source
files and the actually running of the examples online. The first
set of examples, after decoding the HTML FORM contents, merely
verifies the text within a field to make sure it is a valid
representation of an integer, without any junk thrown in, i.e. it
must satisfy the regular expression: ^ *?+ *$
If the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |