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! - Dim db As Database
-
Dim rst As Recordset
-
Dim rst2 As Recordset
-
Dim rst3 As Recordset
-
Dim IntPONo As Integer
-
Dim strSQL As String
-
Dim PO As String
-
-
DoCmd.SetWarnings False
-
-
Set db = CurrentDb()
-
Set rst = db.OpenRecordset("SELECT * FROM pordhdr")
-
-
'If the PONo is NULL then you can not Assign to the Stock Details
-
'Else INSERT INTO pordhdr the SuppNo, PODate and DueDate to create a PONo
-
- If [txtPONo] > 0 Then
-
MsgBox "You CANNOT GENERATE Another Purchase Order to this Order when ONE ALREADY EXISTS!", vbCritical, "Purchase Order Creation Error!"
-
Exit Sub
-
-
Else
-
-
rst.Edit
-
strSQL = "INSERT INTO pordhdr ([SuppNo],[PODate],[DueDate]) SELECT forms!frmPOGenerator!txtSuppNo AS SuppNo,[OrderDate],[DueDate] FROM ordhdr WHERE ordhdr.OrderNo = forms!frmPOGenerator!txtOrderNo"
-
DoCmd.RunSQL strSQL
-
rst.update
-
rst.Close
-
-
Set rst3 = db.OpenRecordset("SELECT * FROM pordhdr")
-
-
'Find the NEW PONo just Assigned to the pordhdr
-
'Display Message with PONo Created
-
-
rst3.MoveLast
-
PO = MsgBox("Purchase Order " & rst3!PONo & " Has Been Created. ", vbOKOnly, "Purchase Order Created")
-
rst3.Close
-
-
Set rst3 = Nothing
-
-
'Find the Last PONo within the pordhdr
-
-
Set rst3 = CurrentDb.OpenRecordset("SELECT * FROM pordhdr")
-
rst3.MoveLast
-
-
Set rst2 = db.OpenRecordset("SELECT * FROM ordlin")
-
-
'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
-
-
rst2.Edit
-
strSQL = "UPDATE ordlin SET [PONo] = '" & rst3!PONo & "' WHERE ([ordlin.OrderNo] = [forms]![frmPOGenerator]![txtOrderNo] And [ordlin.SuppNo] = [forms]![frmPOGenerator]![txtSuppNo] AND ((ordlin.PONo) Is Null))"
-
DoCmd.RunSQL strSQL
-
rst2.update
-
rst2.Close
-
rst3.Close
-
-
Set rst2 = Nothing
-
Set rst3 = Nothing
-
-
DoCmd.SetWarnings True
-
-
'Refresh the List Box
-
-
lstSuppNoSelect.Requery
-
- 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?
4 1422
Try changing your first 4 lines of code to the following and see what happens. -
Dim db As DAO.Database
-
Dim rst As DAO.Recordset
-
Dim rst2 As DAO.Recordset
-
Dim rst3 As DAO.Recordset
Try changing your first 4 lines of code to the following and see what happens. -
Dim db As DAO.Database
-
Dim rst As DAO.Recordset
-
Dim rst2 As DAO.Recordset
-
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.
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: -
If [txtPONo] > 0 Then
-
MsgBox "You CANNOT GENERATE Another Purchase Order to this Order when ONE ALREADY EXISTS!", vbCritical, "Purchase Order Creation Error!"
-
Exit Sub
-
-
ElseIf IsNull(PONo) Then
-
MsgBox " The PO Number is missing. Can't assign stock details."
-
Exit Sub
-
Else
In addition to the above changes, change lines 15 thru 21 of your code to the following: -
If [txtPONo] > 0 Then
-
MsgBox "You CANNOT GENERATE Another Purchase Order to this Order when ONE ALREADY EXISTS!", vbCritical, "Purchase Order Creation Error!"
-
Exit Sub
-
-
ElseIf IsNull(PONo) Then
-
MsgBox " The PO Number is missing. Can't assign stock details."
-
Exit Sub
-
Else
Yeah thanks that worked a treat.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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)
|
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...
|
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
|
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
|
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...
| |
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 ...
|
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...
|
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.
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |