Can I do this?

mcregan

New member
Local time
Today, 20:08
Joined
Sep 21, 2001
Messages
6
Currently I use a form to enter data about the sale of pest bait in a given area. I want the form to alert me when I sell bait in specific sub-quadrants of the given area. So I enter the quadrant of the address baised upon a grid and if it matches a certain list of quadrants then I am somehow informed of that. Is this possible?
 
I am assuming that you have some way of deriving the subset of quadrants that match what you are looking for (a query perhaps). In the AfterUpdate event of when you enter the data in the form, simply put
Code:
If Me.Quadrant = Your Criterion Then MsgBox "It meets the criteria."

or

Code:
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("YourQueryName", dbOpenDynaset)
rs.FindFirst "[Quadrant]= " & YourControlName
If rs.NoMatch Then Exit Sub
MsgBox "This record is in the quadrant."
 
Ok, I think I'm on the right track, but I still need a little help. I went under build event, then code builder and I entered the code you gave me and I got an error message. For the If rs.NoMatch then Exit line a error popped up that says : complie error: Expected: Do or For or Sub or Function or Property.

Am I close here, or should I be doing something else?
 
Where did you put the code? For which event on which control?

It sounds like you are not at all familiar with VBA. I would encourage you to look through the help files, this forum and others to learn a little more about it.
 
mcregan,

a couple of questions: is your list of quadrants in a separate table?

(also is pest bait available for humans?...i may have some use for it.)


al


[This message has been edited by pcs (edited 09-22-2001).]
 
Yes the list of quadrants is is a separate table, and I don't think the bait will work for humans.

I entered the code for afterevent. There are no longer error messages in the code, but when I enter a number in the field of the form it takes me to the VBA screen and gets angry with the Dim db as Database. Do I need to tell it which database at this point?

I don't know a lot about VBA and from what I've read in the help boxes I still don't know much about it.

[This message has been edited by mcregan (edited 09-24-2001).]

[This message has been edited by mcregan (edited 09-24-2001).]

[This message has been edited by mcregan (edited 09-24-2001).]
 
I don't have 2000 but from what I've read here it's something like Dim db As DAO Database if you search the forum it has been answered recently and I think by Pat Hartman.
HTH
 
It likely has to do with the References (Tools-References in VBA). Check off the following:

Microsoft DAO 3.6 Object Library
Microsoft VBScript Regular Expressions

What is happening is that you are telling to make the variable 'db' a 'Database' but it doesn't know what a 'Database' is unless you refer to the library that defines it. That's what references are all about.

HTH
 
Ok, that did the trick for the problem I was having, now it hangs up at the find first command. Does my recordset need to be a query, or is it fine if it is a table?

Is there a book or tool of some sort that you recomend to learn more about VBA and access in general? It seems that most of the books I have seen are very basic and are based on examples of generic situations. They walk me through making a table or a simple form but I can already do these things. I want something that gets into the little quirks of access.
 
I wish there was some reference to say "If you want to use this command, you need this dll referenced." Haven't found it yet. I generally just play hit and miss to get the reference I want. Here are a couple more that I have that may fix the FindFirst problem:

OLE Automation
Microsoft Visual Basic for Applications Extensibility 5.3
Microsoft VBScript Global

Again, I don't know if I have guessed right here or not, but see if that works.

I know your frustration with learning this stuff. It can be defeating. But please continue on. It is so very worth it in the end.

I have learned much from websites (including this one), the help files (the Visual Basic help files) and from just plain old trial and error!

Good luck!
 

Users who are viewing this thread

Back
Top Bottom