473,378 Members | 1,429 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,378 software developers and data experts.

Help with a where condition

Hi everyone,

I need help with a database i'm working on. It is almost fully fonctionnal. I have a form that is a menu and this form contains command buttons. Most of them work, but I cannot get one to do what I want. I need to be able to click on the button and when I do it ask me a number (3 or 4 characters). It then displays a report with the contract numbers ending with this number I just entered. I tried entering a where condition with a like "*[Lot]" ([Lot] being the name of that field with the 3 or 4 characters), but this does not work. I have other buttons that work almost like this one, but I enter the whole contract number so it works fine. The problem is really when I need to find all the contracts ending with the same numbers.

Right now my where condition in access for the bouton is : Report![RapportProjet]![Contrat] like "*[Lot]" (my database is french so the names of the fields and tables are french) Lot is a text box in the report so when I open it, it asks me what value I want. I enter 104B (for example). I then want all of the entries with a contract number ([contrat]) ending with 104B to appear in the report and not the other entries.

I hope you understand my problem and will be able to help me.

David
Jul 13 '11 #1
12 2237
NeoPa
32,556 Expert Mod 16PB
Where are you putting the WHERE condition David?

I would expect this to be a filter applied to the opening of the report. In that case the left-side of the comparison should be unqualified ([Contrat]) whereas the right-side should be qualified and outside of the quotes. I have no reference to your form but it might be something like :
Expand|Select|Wrap|Line Numbers
  1. "[Contrat] Like '*' & Forms!YourForm.Lot"
If this is always triggered on the fly then an easier approach would be to set up the string in your VBA using the literal value :
Expand|Select|Wrap|Line Numbers
  1. strFilter = "[Contrat] Like '*" & Forms!YourForm.Lot & "'"
Jul 13 '11 #2
I put the condition in the macro window (see image)

. Of course I'm french so the window might seem a little different than yours because of the text but the code I entered is what I wrote in my first post. For my other buttons (the ones that work) I wrote: [TableDeficiences]![Contrat]=[Forms]![FormulaireDeficiences]![Contrat]![Reports]![PetitRapport]![Étiquette27]

This then asks me what contract I want from my table and from the form and displays only these in the report. HoweverI cannot seem to get it to work when I just want the last numers of the contract and not the whole thing.
Jul 14 '11 #3
Mihail
759 512MB
I think that you make a little mistake:
The WHERE condition must be a string, isn't it ?
So, "*[Lot]" IS a string (with the characters as you see: *[LOT].

Try that:
Declare a STRING variable (Say S).
Assign to this variable the value: S = "Like *" & [LOT].
Use this variable as your WHERE condition.

Good luck !
Jul 14 '11 #4
Ok, I'm guessing this must be in the Visual Basic code so I remved it from the where and wrote this in the onClick event of the button :

However, an error message pops up (error 2465) and it does not seem to work. Am I doing something wrong? The [Lot] is not in any tables. I just added it in the report so it asks which value I want when I open it and displays it on the report. Could this be the probem? I really appreciate your help by the way.

David
Jul 14 '11 #5
NeoPa
32,556 Expert Mod 16PB
David, we have code windows for displaying code. Yours is legible, but unusual. Code windows work better in here.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command64_Click()
  2.  
  3.     Dim strSQL As String
  4.     strSQL = "[Contrat] Like '*" & Me.Lot & "'"
  5.     Call DoCmd.OpenReport(RapportProjet, acViewDesign, , strSQL, acWindowNormal)
  6.  
  7. End Sub
This is what I was saying in post #2, but I didn't have the context then to narrow it down quite this far (Me.Lot only works when you are running the code from the same form that [Lot] is a control of).
Jul 14 '11 #6
I tried your code and the problem is with the Me.Lot. Lot is not in any of the tables I made and it is not it the form either. I used a text box in the report and named it Lot. When I try to open the report, it asks me which Lot number I want. How do I make the code work in this case?
Jul 14 '11 #7
Rabbit
12,516 Expert Mod 8TB
If you don't have the Lot field in any of your tables, how exactly did you plan on filtering by it? An object must exist for an action to be performed on it.
Jul 14 '11 #8
NeoPa
32,556 Expert Mod 16PB
David, This is all about the lack of important information that you should have included in the question. I read your post #5 and, although it didn't explain where [Lot] came from, it did rather imply it was on the local form (How else would your reference make any sense). What you explain doesn't. I expect that's because you're a little confused about how the filtering works.

Basically, the filter is applied to the record source of the report. The assumption I was working to was that [Contrat] is a field in that recordset. The filter works by saying :
"Show only the records where the field [Contrat] matches certain specified criteria."

I assume you can see how that would make little sense if the criteria were comparing it with something that cannot be determined until after the filtering has been applied. Frankly, although you haven't explained your data structure very fully, I don't expect there are many situations where it even makes sense to compare one field in a record with another (although that is at least feasible), as you appear to want to do.

Why don't you explain what it is you are trying to achieve and we can try again actually knowing what the situation is. That may help.
Jul 14 '11 #9
Mihail
759 512MB
I think (yet) that is a syntax error. "Lot" it is an anbound text box. So [Lot] is an incorrect syntax. Retry NeoPa's code but replace (or add) Me.Lot with Me.Lot.Text (or, simply, Lot.Text).
Jul 15 '11 #10
Ok. What I'm trying to achieve is that when I click on a button in a form I made called FrmMenu (there are only buttons in this form. No data entry) I want it to ask the user what lot number he wants. Then with that number, it finds all the contracts from the table and displays only the ones ending with the lot number specified (because the contracts have the form XX-X-XXX and the last 3 X are the lot number). I also want to have the lot number the entered appear in the report header and that is why I put a text box with a tag up there named lot. So when I would open the report it would ask me a lot number because it cannot find any in the tables (because it isn't in any table). I'm pretty sure there is an easier way of doing this, but I'm pretty new to VBA coding and ok with sql and other database stuff.
Jul 15 '11 #11
Mihail
759 512MB
Take a look here:

http://bytes.com/topic/access/answer...-textbox-query

and here:

http://bytes.com/topic/access/answer...control-values

I am pretty sure that you find the answer.
Remember: To open an report, Access must evaluate the query. So the QUERY must know the "Lot" value, not the report after.
Jul 15 '11 #12
NeoPa
32,556 Expert Mod 16PB
David, you need a TextBox control on your form (or one of your forms).

If you really don't want the [Lot] box on your menu form then get the command button to open a separate form specially for this report. That seems somewhat clumsier to me (than having it on FrmMenu), but it's your project, so your choice.

Ultimately, whichever form it is on should have the code that opens the report within it. The code will look very much like the code I posted for you earlier in post #6. I can't guarantee the Command Button will have the same name as before (very unlikely in fact) but otherwise it's all there.

Bonne chance!
Jul 15 '11 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: lorirobn | last post by:
Hello, I'd be curious to hear other thoughts on my database and table design. My database is for 'space use' in a lodging facility - will hold all spaces, like rooms (lodging rooms, dining...
3
by: Shawn | last post by:
Hello all... I'm new to the world of C programming, and am working with an embedded microcontroller as a hobby. I have a reasonably simple program running now, but I'm having trouble figuring...
1
by: Jo | last post by:
I am having a real problem with the Launch conditions in VS .NET and can only come to the conclusion that it is a bug. It states quite emphatically in the MSDN that Launch Conditions WILL be...
1
by: ggiano | last post by:
Hi, My application have two threads that run at the same time. This is my code Public WithEvents tww1 As New ThreadWrapp1 Public t1 As New Thread(AddressOf tww1.Ask) Public WithEvents...
4
by: joh12005 | last post by:
Hello, i posted for suggestions a little idea even if it still needs further thoughts but as i'm sure you could help :) if would like to implement some kind of Condition class which i coud...
1
by: anadiks | last post by:
Problem 2: Threading: Requirements: In a particular system there are two threads T1 and T2. T1 is the master thread that periodically sends messages to the worker thread T2. The system...
5
by: jimc52 | last post by:
Hello Everyone: I am hoping one of the gurus here will give me some help. I have designed a form with some check boxes. I put the checkboxes there on the form so later I could use them as flags on...
5
by: Samik2003 | last post by:
Hello, The problem is my query is not extracting the correct xml data from the database : Is there something which I am missing?? ANy help would be appriciated. Thanks, Sam. THis is the...
0
by: RN1 | last post by:
I have a DataGrid with an EditCommandColumn. In the EditCommand sub of the DataGrid, there is an If condition. This If condition is True for some rows in the DataGrid whereas it is False for the...
0
by: stylishjm | last post by:
I have tried asking for help on multiple forums including VB with no responses. Anyway my problem is that Im attempting to create a simple music file hosting website using vBulletin 4 with the use...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.