I am trying to run a module from a button on a form where I populate a subform from Query1 with a product formula. The module is supposed to check whether the product formula can be implemented given enough raw material inventory. So, I'm trying to loop through my product formula based on OrderID and MaterialID(Material Name) and check against the current stock inventory table. If any of the ingredients required for the product to be made is over the available stock inventory on hand, then I want an error to be displayed, otherwise I don't want any errors.
The problem I'm having is with the Compile Error at the line where it states:
I'd appreciate any help possible, THANKS!!
The entire code is as follows: -
Option Compare Database
-
Option Explicit
-
-
Sub check_quantity()
-
On Error GoTo err_check_quantity
-
-
Dim material As Variant
-
Dim totalKg As Variant
-
queryString As String
-
queryString2 As String
-
Quantity As Variant
-
valid As Integer
-
strMsg As String
-
Dim Rs As DAO.Recordset
-
Dim Rs2 As DAO.Recordset
-
Dim Db As DAO.Database
-
-
-
Set Db = CurrentDb()
-
-
queryString = "SELECT * FROM Query1 WHERE [ProductName] = '" & [Forms]![Batchsheet Subform]![ProductName] & "' AND [OrderID] = " & [Forms]![Batchsheet Subform]![OrderID] & ";"
-
-
Set Rs = Db.OpenRecordset(queryString, dbOpenDynaset)
-
-
If Not (Rs.BOF And Rs.EOF) Then
-
Rs.MoveLast
-
Rs.MoveFirst
-
-
With Rs
-
Do While Not Rs.EOF
-
-
material = Rs.Fields("MaterialID").Value
-
totalKg = Rs.Fields("Total (kg)").Value
-
-
queryString2 = "SELECT * FROM RawMaterials WHERE [ItemName] = '" & material & ";"
-
-
Set Rs2 = Db.OpenRecordset(queryString2, dbOpenDynaset)
-
-
If Not (Rs2.BOF And Rs2.EOF) Then
-
Rs2.MoveLast
-
Rs2.MoveFirst
-
-
-
Quantity = Rs2.Fields("InStock").Value
-
-
-
If totalKg > Quantity Then
-
valid = 0
-
Else
-
valid = 1
-
End If
-
-
Select Case valid
-
-
Case 0
-
strMsg = " Order cannot currently be completed" & _
-
vbCrLf & " Please verify you have enough " & material & "inventory to complete this order."
-
MsgBox strMsg, vbInformation, "INVALID Raw Material Level"
-
-
Case 1
-
Rs.MoveNext
-
-
End Select
-
-
Loop
-
End With
-
-
-
Rs.Close
-
Rs2.Close
-
Db.Close
-
-
Set Rs = Nothing
-
Set Rs2 = Nothing
-
Set Db = Nothing
-
-
exit_check_quantity:
-
Exit Sub
-
-
err_check_quantity:
-
MsgBox Err.decsription
-
Resume exit_check_quantity
-
-
End Sub
-
-
NeoPa: Your Do...Loops, and If...End Ifs, and With...End Withs do not balance up correctly.
You need to get these sorted before continuing, and certainly before it will work.
Welcome to Bytes!
I would add : - Line #75 closes CurrentDB. Not a good idea. If your code opens an object then it should close it. If it finds it already open, then it should leave it open. There may be exceptions to this rule, but they're rare.
- Line #81 is probably the offending property. You want Err.Description.
Remember next time to include the line number though please. 9 8125
Ok, it looks like I forgot some Dim's. Fixed that but now my new error is "Loop without Do" Hmmm, I see a Do, but maybe I'm not closing or opening the loop properly?
NeoPa 32,556
Expert Mod 16PB
Your Do...Loops, and If...End Ifs, and With...End Withs do not balance up correctly.
You need to get these sorted before continuing, and certainly before it will work.
Welcome to Bytes!
Ok, looks like I've fixed the loop problems. Now, I am getting a message box popup that states, "Object Doesn't Support This Property or Method".
I'm guessing the problem is either with a type mismatch where I may be comparing a string to a number or vice versa. Or maybe somehow the fact that I am retrieving values from a Query is causing the problem?
Can anyone offer any insight?
The feedback so far is really appreciated.
Thanks!
Updated Code: -
Option Compare Database
-
Option Explicit
-
-
Sub check_quantity()
-
On Error GoTo err_check_quantity
-
-
Dim material As String
-
Dim totalKg As Variant
-
Dim queryString As String
-
Dim queryString2 As String
-
Dim Quantity As Variant
-
Dim valid As Integer
-
Dim strMsg As String
-
Dim Rs As DAO.Recordset
-
Dim Rs2 As DAO.Recordset
-
Dim Db As DAO.Database
-
-
valid = 1
-
-
Set Db = CurrentDb()
-
-
queryString = "SELECT * FROM Query1 WHERE [ProductName] = '" & [Forms]![Batchsheet Subform]![ProductName] & "' AND [OrderID] = " & [Forms]![Batchsheet Subform]![OrderID] & ";"
-
-
Set Rs = Db.OpenRecordset(queryString, dbOpenDynaset)
-
-
If Not (Rs.BOF And Rs.EOF) Then
-
Rs.MoveLast
-
Rs.MoveFirst
-
-
With Rs
-
Do While Not Rs.EOF
-
-
material = Rs.Fields("MaterialID").Value
-
totalKg = Rs.Fields("Total (kg)").Value
-
-
queryString2 = "SELECT * FROM RawMaterials WHERE [ItemName] = '" & material & ";"
-
-
Set Rs2 = Db.OpenRecordset(queryString2, dbOpenDynaset)
-
-
If Not (Rs2.BOF And Rs2.EOF) Then
-
Rs2.MoveLast
-
Rs2.MoveFirst
-
-
Quantity = Rs2.Fields("InStock").Value
-
-
-
If totalKg > Quantity Then
-
valid = 0
-
Else
-
valid = 1
-
End If
-
-
Select Case valid
-
-
Case 0
-
strMsg = " Order cannot currently be completed" & _
-
vbCrLf & " Please verify you have enough " & material & "inventory to complete this order."
-
MsgBox strMsg, vbInformation, "INVALID Raw Material Level"
-
Exit Do
-
-
Case 1
-
Rs.MoveNext
-
-
End Select
-
-
End If
-
-
Loop
-
End With
-
-
End If
-
-
Rs.Close
-
Rs2.Close
-
Db.Close
-
-
Set Rs = Nothing
-
Set Rs2 = Nothing
-
Set Db = Nothing
-
-
exit_check_quantity:
-
Exit Sub
-
-
err_check_quantity:
-
MsgBox Err.decsription
-
Resume exit_check_quantity
-
-
End Sub
-
NeoPa 32,556
Expert Mod 16PB
The error message is good. Giving the line the error occurred on would also be a great help. The code box helps by numbering each line for you.
NeoPa 32,556
Expert Mod 16PB NeoPa: Your Do...Loops, and If...End Ifs, and With...End Withs do not balance up correctly.
You need to get these sorted before continuing, and certainly before it will work.
Welcome to Bytes!
I would add : - Line #75 closes CurrentDB. Not a good idea. If your code opens an object then it should close it. If it finds it already open, then it should leave it open. There may be exceptions to this rule, but they're rare.
- Line #81 is probably the offending property. You want Err.Description.
Remember next time to include the line number though please.
Thanks NeoPa,
Unfortunately my error message didn't provide a line number, otherwise I would have definitely included it. Let me try your suggestions and get back to you.
Thanks so much for the help so far.
Ok, I corrected the typo with description but yet again I have another error. I'm getting an error that states: "Microsoft Office Access can't find the form 'BatchsheetSubform' referred to in a macro expression or Visual Basic code." Again, no error number or line number, but it's obvious which line is the offending one here.
I changed the name of the Batchsheet subform to BatchsheetSubform thinking that the space was causing a problem because VB was automagically using an uppercase 'S' for Subform. And my actual form uses a lower case 's'. Now I've just renamed the form to 'BatchsheetSubform both in VB and in the actual form.
I also added .[Form] to reference the control in the subform since I believe a subform is a control in itself and needs a .Form to access it's controls. I also did away with Db.close but that didn't help.
Updated Code: -
Option Compare Database
-
Option Explicit
-
-
Sub check_quantity()
-
On Error GoTo err_check_quantity
-
-
Dim material As String
-
Dim totalKg As Variant
-
Dim queryString As String
-
Dim queryString2 As String
-
Dim Quantity As Variant
-
Dim valid As Integer
-
Dim strMsg As String
-
Dim Rs As DAO.Recordset
-
Dim Rs2 As DAO.Recordset
-
Dim Db As DAO.Database
-
-
valid = 1
-
-
Set Db = CurrentDb()
-
-
queryString = "SELECT * FROM Query1 WHERE [ProductName] = '" & [Forms]![BatchsheetSubform]![Form]![ProductName] & "' AND [OrderID] = " & [Forms]![Batchsheet Subform]![OrderID] & ";"
-
-
Set Rs = Db.OpenRecordset(queryString, dbOpenDynaset)
-
-
If Not (Rs.BOF And Rs.EOF) Then
-
Rs.MoveLast
-
Rs.MoveFirst
-
-
With Rs
-
Do While Not Rs.EOF
-
-
material = Rs.Fields("MaterialID").Value
-
totalKg = Rs.Fields("Total (kg)").Value
-
-
queryString2 = "SELECT * FROM RawMaterials WHERE [ItemName] = '" & material & ";"
-
-
Set Rs2 = Db.OpenRecordset(queryString2, dbOpenDynaset)
-
-
If Not (Rs2.BOF And Rs2.EOF) Then
-
Rs2.MoveLast
-
Rs2.MoveFirst
-
-
Quantity = Rs2.Fields("InStock").Value
-
-
-
If totalKg > Quantity Then
-
valid = 0
-
Else
-
valid = 1
-
End If
-
-
Select Case valid
-
-
Case 0
-
strMsg = " Order cannot currently be completed" & _
-
vbCrLf & " Please verify you have enough " & material & "inventory to complete this order."
-
MsgBox strMsg, vbInformation, "INVALID Raw Material Level"
-
Exit Do
-
-
Case 1
-
Rs.MoveNext
-
-
End Select
-
-
End If
-
-
Loop
-
End With
-
-
End If
-
-
Rs.Close
-
Rs2.Close
-
Db.Close
-
-
Set Rs = Nothing
-
Set Rs2 = Nothing
-
Set Db = Nothing
-
-
exit_check_quantity:
-
Exit Sub
-
-
err_check_quantity:
-
MsgBox Err.Description
-
Resume exit_check_quantity
-
-
End Sub
-
Ahhh, ok I had to make a few changes but I got it to work!! Thanks a lot for guiding me in the right direction. Really appreciate it!
NeoPa 32,556
Expert Mod 16PB
Well done for finding and fixing all the errors Amit.
I agree with your earlier comment. If no line number is reported, then you cannot pass it on. Always do so when you can though :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: xuatla |
last post by:
Hi,
I encountered the following compile error of c++ and hope to get your help.
test2.cpp: In member function `CTest CTest::operator+=(CTest&)':
test2.cpp:79: error: no match for 'operator='...
|
by: Brice Prunier |
last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...)
The context is the following :
Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema:
no TargetNamespace )...
|
by: Peter |
last post by:
Hi,
I am trying to compile an existing project (originally c) in .NET (rename .c
files to .cpp). After fixing some problems, here are the ones that I don't
know how to deal with:...
|
by: Michael D. Reed |
last post by:
I have a C++ program that I am trying to get to compile and link in VS2003.
It is an old windows program that was built and maintained with older
versions of VS and VC++. I made the necessary...
|
by: David |
last post by:
I am getting the following error during run-time
compilation or a rebuild all of my application:
error BC30311: Value of type 'mynamespace.x' cannot be
converted to 'mynamespace.x'
This...
|
by: vfunc |
last post by:
I get a compile error at line 285 of this demo
error converting from void* to pollfd*
Do I need to set some compiler flag ?
I did not write this so I'm reluctant to change anything.
251...
|
by: andrewcw |
last post by:
I am moving some code forward from .NET 1.1. I was able to load the XSL file
and perform the transform. The MSDN documentation looks like it should be
easy. But I get a compile error. Ideas ?...
|
by: Light1 |
last post by:
My form (frmERLogs) for this project (ER Log Book) has a combo box (cboMedicalRecordNumber) that I want to be able to double click on to bring up a new form (frmPatientInformation) when a name is not...
|
by: MLH |
last post by:
I have tested the following in immed window:
?isnumeric(1)
True
?isnumeric(1.)
True
?isnumeric(1.2)
True
?isnumeric(1.2.2)
|
by: squrel |
last post by:
Hello All..
I m having some problem here.. i m using VB6 and SQLServer 2000... i m getting this error " statement invalid outside type block"
i m sending u the code and the bold line is where i m...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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,...
|
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...
| |