473,806 Members | 2,319 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating Error Procedures for Grouped Data

129 New Member
Hi I am trying to input some error messages into my system. I have come across a slight problem with one of them. i have a query which filters and groups data together displaying details on a form. I then have a button called "Generate" which looks up the last entry from a particular table to assign a Purchase number to the grouped record. This way its assigns the value to all relevant records. This works by the way! However when i tried to incorporate error procedures into the code i receive type mismatch or false error. The field i generate and base my code on is a Number field. Here is my coding!

Expand|Select|Wrap|Line Numbers
  1. Dim db As Database
  2.     Dim rst As Recordset
  3.     Dim rst2 As Recordset
  4.     Dim rst3 As Recordset
  5.     Dim IntPONo As Integer
  6.     Dim strSQL As String
  7.     Dim PO As String
  8.  
  9.     DoCmd.SetWarnings False
  10.  
  11.     Set db = CurrentDb()
  12.     Set rst = db.OpenRecordset("SELECT * FROM pordhdr")
  13.  
  14.     'If the PONo is NULL then you can not Assign to the Stock Details
  15.     'Else INSERT INTO pordhdr the SuppNo, PODate and DueDate to create a PONo
  16.  
  17.     If [txtPONo] > 0 Then
  18.         MsgBox "You CANNOT GENERATE Another Purchase Order to this Order when ONE ALREADY EXISTS!", vbCritical, "Purchase Order Creation Error!"
  19.         Exit Sub
  20.  
  21.     Else
  22.  
  23.     rst.Edit
  24.     strSQL = "INSERT INTO pordhdr ([SuppNo],[PODate],[DueDate]) SELECT forms!frmPOGenerator!txtSuppNo AS SuppNo,[OrderDate],[DueDate] FROM ordhdr WHERE ordhdr.OrderNo = forms!frmPOGenerator!txtOrderNo"
  25.     DoCmd.RunSQL strSQL
  26.     rst.update
  27.     rst.Close
  28.  
  29.     Set rst3 = db.OpenRecordset("SELECT * FROM pordhdr")
  30.  
  31.     'Find the NEW PONo just Assigned to the pordhdr
  32.     'Display Message with PONo Created
  33.  
  34.     rst3.MoveLast
  35.         PO = MsgBox("Purchase Order " & rst3!PONo & " Has Been Created. ", vbOKOnly, "Purchase Order Created")
  36.     rst3.Close
  37.  
  38.     Set rst3 = Nothing
  39.  
  40.     'Find the Last PONo within the pordhdr
  41.  
  42.     Set rst3 = CurrentDb.OpenRecordset("SELECT * FROM pordhdr")
  43.     rst3.MoveLast
  44.  
  45.     Set rst2 = db.OpenRecordset("SELECT * FROM ordlin")
  46.  
  47.     'UPDATE the PONo Field (Based on SuppNo and OrderNo with the last PONo above) within the ordlin Table therefore Assigning the Stock Details with a Purchase Order
  48.  
  49.     rst2.Edit
  50.     strSQL = "UPDATE ordlin SET [PONo] = '" & rst3!PONo & "' WHERE ([ordlin.OrderNo] = [forms]![frmPOGenerator]![txtOrderNo] And [ordlin.SuppNo] = [forms]![frmPOGenerator]![txtSuppNo] AND ((ordlin.PONo) Is Null))"
  51.     DoCmd.RunSQL strSQL
  52.     rst2.update
  53.     rst2.Close
  54.     rst3.Close
  55.  
  56.     Set rst2 = Nothing
  57.     Set rst3 = Nothing
  58.  
  59.     DoCmd.SetWarnings True
  60.  
  61.     'Refresh the List Box
  62.  
  63.     lstSuppNoSelect.Requery
  64.  
  65.     End If
From the Image where there is a NULL entry i want the main code to work and if they click on an entry where data is present then do nothing.

Ignore the main detail of code as that is fine, please just look at the if statement and the screenshot, any advice would be much appreciated?
Attached Images
File Type: bmp untitled.bmp (17.2 KB, 197 views)
Oct 2 '08 #1
4 1422
puppydogbuddy
1,923 Recognized Expert Top Contributor
Try changing your first 4 lines of code to the following and see what happens.
Expand|Select|Wrap|Line Numbers
  1.     Dim db As DAO.Database 
  2.     Dim rst As DAO.Recordset 
  3.     Dim rst2 As DAO.Recordset 
  4.     Dim rst3 As DAO.Recordset 
Oct 3 '08 #2
Constantine AI
129 New Member
Try changing your first 4 lines of code to the following and see what happens.
Expand|Select|Wrap|Line Numbers
  1.     Dim db As DAO.Database 
  2.     Dim rst As DAO.Recordset 
  3.     Dim rst2 As DAO.Recordset 
  4.     Dim rst3 As DAO.Recordset 
Nope no luck it brings up the error message for both circumstances instead of one of them. It is as if the grouped data with NO PONo assigned to them are taking space with something causing the error to run. The record is blank though as you can see from the screenshot.
Oct 3 '08 #3
puppydogbuddy
1,923 Recognized Expert Top Contributor
Nope no luck it brings up the error message for both circumstances instead of one of them. It is as if the grouped data with NO PONo assigned to them are taking space with something causing the error to run. The record is blank though as you can see from the screenshot.
In addition to the above changes, change lines 15 thru 21 of your code to the following:

Expand|Select|Wrap|Line Numbers
  1. If [txtPONo] > 0 Then 
  2.  MsgBox "You CANNOT GENERATE Another Purchase Order to this Order when ONE ALREADY EXISTS!", vbCritical, "Purchase Order Creation Error!" 
  3.             Exit Sub 
  4.  
  5. ElseIf  IsNull(PONo) Then
  6.     MsgBox " The PO Number is missing. Can't assign stock details."   
  7.     Exit Sub
  8. Else 
Oct 3 '08 #4
Constantine AI
129 New Member
In addition to the above changes, change lines 15 thru 21 of your code to the following:

Expand|Select|Wrap|Line Numbers
  1. If [txtPONo] > 0 Then 
  2.  MsgBox "You CANNOT GENERATE Another Purchase Order to this Order when ONE ALREADY EXISTS!", vbCritical, "Purchase Order Creation Error!" 
  3.             Exit Sub 
  4.  
  5. ElseIf  IsNull(PONo) Then
  6.     MsgBox " The PO Number is missing. Can't assign stock details."   
  7.     Exit Sub
  8. Else 
Yeah thanks that worked a treat.
Oct 3 '08 #5

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

Similar topics

0
1995
by: Alan Cobban | last post by:
Hello, I'm in the process of tuning our auditing procedures. At present we have one table, mp_event_audits which holds username, date/time, change type, data changed etc columns - DEV> desc mp_event_audits Name Null? Type ------------------------------- -------- ---- EA_ID NOT NULL NUMBER(8)
3
2786
by: Robin Tucker | last post by:
Hi there, I have a database on my test machine that will need to be installed on users machines. I would like to create the database with the given schema on the users machine and also with some suitable default values in the tables. I note that although I can script the schema so that re-creating the structure of the database is simple on the users machine, I cannot script the contents of the tables also (automatically). What I would...
3
2402
by: serge | last post by:
I have all the scrips to create a database. I have a few questions: 1- I am creating a batch file that it will call many lines like: db2 -td@ -f filename.sql -z output.txt The order i am using is: 1- Create the database 2- Tables 3- Insert the data
6
4766
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
4
1587
by: Jimmer | last post by:
How does one create/change a form on the fly? I have a situation where I would like the user to be able to determine the fields they view and how the data is grouped at runtime. For example, the form might list Company Name, Last Name, Address, Phone Number, Accounts Payable $ on time and Last Name, Address, Phone Number, Social Security, Accounts Payable $ the next and Company Name and Accounts Payable $ the time after that. Each one...
2
1908
by: Chris via AccessMonster.com | last post by:
I have done something like this a million years ago my developer skills have diminished to nothing but now I am at a new job trying to regroup what I lost. This one came across my desk recently. I need to create tables based on grouped recordsets the additional challenge is that the table name would equal the value or variable of the grouped recordset. Example below Field_1 Field_2 Field_3 email@email.com Boston ...
13
4491
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently runs into problems on the system where it will actually be used, and since I used so little error-trapping it dies very ungracefully. I will of course try to fix whatever is causing the error and add error-trapping to the functions where the...
2
6080
by: Andy | last post by:
Hi guys I having a problem creating a report in Access 2003 project talking to a SQL database through and ODBC connect. After hours of trying things from Access Help, MSDN and Google I still can't get it working. I have a query defined (view) and want the end user to put in a start date and end date to filter a report.
8
30068
by: nico3334 | last post by:
I have a database that has a Date column (1/1/2007) and a Data column that has numerical data. I am currently running a query to sum the Data column for a certain month and grouped by day (There is more than items of Data for a specific Day). Here is my current query: SELECT SUM(Data) as Total FROM database WHERE Month(Date) = 10 And Year(Date) = 2007 Group by Day(Date) This displays the summed data which is grouped by the Days of...
0
10618
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, 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...
0
10110
tracyyun
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...
0
9187
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
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 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...
0
6877
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();...
0
5546
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...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.