473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

code doesn't work on some PC's; does on others

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 "whencondition" 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_Search!txtSubject.Text
category = Forms!frm_Search!cmbCategory.Text
DoCmd.OpenForm FormName:="frm_Browse", view:=acNormal,
wherecondition:= category & " Like " & Chr$(34) & "*" & subject &
"*" &
Chr$(34)

End Sub

Nov 13 '05 #1
6 1850
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 "whencondition" 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_Search!txtSubject.Text
category = Forms!frm_Search!cmbCategory.Text
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.Value 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.Value
& "*" & Chr(34)

or

wherecondition := "Subject Like " & Chr(34) & "*" & txtSubject.Value &
"*" & Chr(34)

or

wherecondition := "(Category Like " & Chr(34) & "*" & cmbCategory.Value
& "*" & Chr(34) & ") AND (" & "Subject Like " & Chr(34) & "*" &
txtSubject.Value & "*" & 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

Nov 13 '05 #2
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.Value is like txtSubject.Value. 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.

Nov 13 '05 #3
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.Value is like txtSubject.Value. 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

Nov 13 '05 #4
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.

Nov 13 '05 #5
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

Nov 13 '05 #6
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 frmSearchResults I now have something like:

Me.RecordSource = GetSearchSQL()
If Me.RecordsetClone.RecordCount = 1 Then
Call cmdSelect_Click
End If

James A. Fortune

Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

242
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...
53
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...
45
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...
1
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?...
11
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...
192
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
15
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...
64
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...
232
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.