473,396 Members | 2,039 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,396 software developers and data experts.

How to make an error box appear when a limit has been reached?

I currently have a form, where the users enter data and loan out books.
I need some way of limiting each user to just 2 books, I have a loan count in a Query called "Bookloans",

when the save record button is clicked, im looking to have an "IF" in the Vba codes that refers to the specific field with the users id, and how many books they have, if this value is equal to 2, then bring up a message error box stating that they have already reached the maximum ammount of books, and close the form, if it is lower, then just save the record

Thanks,
Dan
Jan 31 '11 #1

✓ answered by NeoPa

OK. I hear you trying to explain as well as you can. Let's see what we can do to assist.

The simple answer is the one I gave in the first response. You need to use DCount() of whatever recordset you have in your database that lists the existing loans.

That's the fundamentals sorted. I will also throw in some points that will help you get to where you want to get to :
  1. Your pseudocode illustration is fundamentally along the right lines. You may want to consider a few amendments though.
  2. If a problem is found, closing the form entirely (DoCmd.Close) is probably not the smoothest way to handle it. Further points below will cover alternatives (in context).
  3. Ask yourself - Do yo want the operator to find out they cannot add a new loan only after they have spent the time filling in the form? If the answer to that is No, and I imagine it must be, then try putting the code somewhere where it will be run whenever a new record becomes current on the form, and then the code would enable or disable the ability for the operator to fill in any details for that record. The code would have to be placed in a common routine and called from the event procedures for opening the form istelf, as well as for when the current record changes. These events are Form_Open() and Form_Current(). The fundamental structure of such code would be :
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Open()
    2.     Call CommonRoutine
    3. End Sub
    4.  
    5. Private Sub Form_Open()
    6.     Call CommonRoutine
    7. End Sub
    8.  
    9. Private Sub CommonRoutine()
    10.     Me.Command20.Enabled = (DCount("*", _
    11.                                    "[BookLoans]", _
    12.                                    {Criteria string}) < 2)
    13. End Sub
    NB. This is simplified to illustrate the concept. I don't know much about your form's design, so you need to incorporate the idea into your code.
  4. The DCount() code requires a knowledge of your data structure to formulate. This is not available to us at this stage.
  5. I assume the query you mention (BookLoans) is the one you need to refer to in the DCount() call. It sounds like this may not be working correctly just yet. If you want help with that you will need to ask for that in a separate thread. We don't like, or allow, multiple questions in the same thread here. You may add a link to your new thread in here if you like.

5 1942
NeoPa
32,556 Expert Mod 16PB
Is the form based on data that includes the number of books loaned to the user? If so, it would make sense to disable the function of the form when a non-qualified user is loaded. If not then a DLookup() or DCount() would be required.

If you feel the answer is very non-specific, then you need to consider how you ask your question. The question has too little detail for a more specific answer.
Jan 31 '11 #2
im sorry i dont know how to explain it properly.

no, the form is based on a table where each student's loans are not counted, its only in a query where i've counted them,

so when i click the save record button on this form, i want it to perform an 'If' that will look into this query, for a field called Loans, and if that answer is equal to 2, open up a message to stay they cant take out anymore,
but if it is less than two, just to carry on with the save

im guessing if i edited the 'save record' buttons code it would be changed to something like:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command20_Click()
  2. On Error GoTo Err_Command20_Click
  3.  
  4.     If ((the link to the existing query, and field, and somehow find that student automaticaly)) Then
  5.     MsgBox "You curretly have the maxiumum number of loans"
  6.     DoCmd.Close
  7.     Else
  8.     DoCmd.RunCommand acCmdSaveRecord
  9.     End If
  10.  
  11. Exit_Command20_Click:
  12.     Exit Sub
  13.  
  14. Err_Command20_Click:
  15.     MsgBox Err.Description
  16.     Resume Exit_Command20_Click
  17.  
  18. End Sub
i hope this makes what im trying to do seem clearer, i cant get the right name of the placing of where the query is, and im currently getting the error "Microsoft Access can't find the field '|1' refered to in your expression.
Feb 1 '11 #3
NeoPa
32,556 Expert Mod 16PB
OK. I hear you trying to explain as well as you can. Let's see what we can do to assist.

The simple answer is the one I gave in the first response. You need to use DCount() of whatever recordset you have in your database that lists the existing loans.

That's the fundamentals sorted. I will also throw in some points that will help you get to where you want to get to :
  1. Your pseudocode illustration is fundamentally along the right lines. You may want to consider a few amendments though.
  2. If a problem is found, closing the form entirely (DoCmd.Close) is probably not the smoothest way to handle it. Further points below will cover alternatives (in context).
  3. Ask yourself - Do yo want the operator to find out they cannot add a new loan only after they have spent the time filling in the form? If the answer to that is No, and I imagine it must be, then try putting the code somewhere where it will be run whenever a new record becomes current on the form, and then the code would enable or disable the ability for the operator to fill in any details for that record. The code would have to be placed in a common routine and called from the event procedures for opening the form istelf, as well as for when the current record changes. These events are Form_Open() and Form_Current(). The fundamental structure of such code would be :
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Open()
    2.     Call CommonRoutine
    3. End Sub
    4.  
    5. Private Sub Form_Open()
    6.     Call CommonRoutine
    7. End Sub
    8.  
    9. Private Sub CommonRoutine()
    10.     Me.Command20.Enabled = (DCount("*", _
    11.                                    "[BookLoans]", _
    12.                                    {Criteria string}) < 2)
    13. End Sub
    NB. This is simplified to illustrate the concept. I don't know much about your form's design, so you need to incorporate the idea into your code.
  4. The DCount() code requires a knowledge of your data structure to formulate. This is not available to us at this stage.
  5. I assume the query you mention (BookLoans) is the one you need to refer to in the DCount() call. It sounds like this may not be working correctly just yet. If you want help with that you will need to ask for that in a separate thread. We don't like, or allow, multiple questions in the same thread here. You may add a link to your new thread in here if you like.
Feb 1 '11 #4
Thank you NeoPa :) i believe it is my query that is currently wrong.

your information has helped alot, and thank you for editing my previous post, I'm new to this website also and hadn't figured out how do the code text layout :)
Feb 1 '11 #5
NeoPa
32,556 Expert Mod 16PB
No worries Dan.

If you'd like me to look at the thread related to the query (if you post one) just pop a link to it in here and I'll take a look.
Feb 2 '11 #6

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

Similar topics

4
by: rod | last post by:
Hello SQL gurus! I am trying to write a query that will return a set of continguous rows from a table, and limit the number of rows returned when a maximum total has been reached by adding a...
6
by: AFN | last post by:
I want to click a checkbox and have a 4 line (approx) paragraph appear beneath the checkbox, pushing the rest of the page down. And when unchecking the checkbox, the paragraph should disappear...
8
by: Andrew Phillipo | last post by:
I have a layout which works perfectly. It is three column, the central column is width:auto; with margins and the columns are absolutely positioned at top:0px; left:0px; and top:0px;right:0px; ...
1
by: intl04 | last post by:
I am getting strange print-related error messages when trying to create (not print!) reports. For example, when I click 'new' to create a report then choose 'design view', I get an error message...
15
by: jane | last post by:
We are getting this error during a large large load. 2006-06-03-02.58.31.688266 Instance:sieinst Node:000 PID:1286274(db2agent (SRMW) 0) TID:1 Appid:GAFE423C.P4CE.0671B3070116 database...
4
by: rdemyan via AccessMonster.com | last post by:
Lately I've been noticing that charts that are created in my application don't always appear. When they don't appear, it is a consistent nonappearance. But then if I close the app and reopen it,...
0
by: oddemann | last post by:
Hi. I have a problem that I can`t find solution to. The errorlog i full of this. 01/11 15:54:15.36 sdpprim sql_agent 27772 SIGNIFICANT sqlsrvr.c 2136 The limit set by...
1
by: yoram.ayalon | last post by:
Hello, we have this situation. web farm, several server 2003 machines, and several win2K, SP 4 machines all machines access files on a Network appliance using CIFS I am testing a ASP.NET...
2
by: alizabeth33 | last post by:
I want to make an image pop up when my text is clicked and I can not figure out how to do that. Instead of having a new page come up, I want just the image to pop up and I know you can do it through...
3
by: dipperdan | last post by:
Hi, I'm getting an error 1064 when trying to delete some rows from a table. SQL is: DELETE FROM images WHERE image_id = 803 AND plant_num = 2277 LIMIT 1; DELETE FROM images WHERE image_id =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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.