473,396 Members | 1,898 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.

Code Problem

Can any one see a problem with this code ( it does not work

Private Sub cmdEmailOrderPlaced_Click()
'On Error GoTo Error_Handler
Dim strTo As String
Dim strBody As String
Dim strSubject As String
Dim strItemsOrdered As String
Dim CRS1 As ADODB.Recordset
Dim strSql As String
Set CRS1 = New ADODB.Recordset

sstrSql = "SELECT * FROM tblOrderProduct WHERE OrderNumber =" &
Me.OrderNumber
CRS1.Open strSql, CurrentProject.Connection, adOpenKeyset,
adLockReadOnly
While Not CRS1.EOF

strItemsOrdered = strItemsOrdered & "Item : " &
DLookup("[ProductName]", "tblProduct", "[ProductCode] =" &
CRS1.Fields("ProductCode"))

strItemsOrdered = strItemsOrdered & "Unit Price : " & Chr(163) &
DLookup("[PriceIncVAT ]", "tblProduct", "[ProductID] =" &
CRS1.Fields("ProductID")) & vbCrLf

'& vbCrLf & "Total Excl VAT: " & Chr(163) &
Format(CRS1.Fields("TotalExVAT"), "##0.00")

If IsNull(CRS1.Fields("Discount")) Or CRS1.Fields("Discount") = 0
Then
'Don't put discount in there if there isn't one
Else
strItemsOrdered = strItemsOrdered & "Discount : " &
CRS1.Fields("Discount") & "%" & vbCrLf
End If
strItemsOrdered = strItemsOrdered & "Total (Inc VAT): " & Chr(163)
& Format(CRS1.Fields("TotalIncVAT"), "##0.00") & vbCrLf & vbCrLf
CRS1.MoveNext
Wend
CRS1.Close
Set CRS1 = Nothing

Aug 12 '06 #1
7 3051
* Simon:
Can any one see a problem with this code ( it does not work

Private Sub cmdEmailOrderPlaced_Click()
'On Error GoTo Error_Handler
Dim strTo As String
Dim strBody As String
Dim strSubject As String
Dim strItemsOrdered As String
Dim CRS1 As ADODB.Recordset
Dim strSql As String
Set CRS1 = New ADODB.Recordset

sstrSql = "SELECT * FROM tblOrderProduct WHERE OrderNumber =" &
Me.OrderNumber
CRS1.Open strSql, CurrentProject.Connection, adOpenKeyset,
adLockReadOnly
While Not CRS1.EOF

strItemsOrdered = strItemsOrdered & "Item : " &
DLookup("[ProductName]", "tblProduct", "[ProductCode] =" &
CRS1.Fields("ProductCode"))

strItemsOrdered = strItemsOrdered & "Unit Price : " & Chr(163) &
DLookup("[PriceIncVAT ]", "tblProduct", "[ProductID] =" &
CRS1.Fields("ProductID")) & vbCrLf

'& vbCrLf & "Total Excl VAT: " & Chr(163) &
Format(CRS1.Fields("TotalExVAT"), "##0.00")

If IsNull(CRS1.Fields("Discount")) Or CRS1.Fields("Discount") = 0
Then
'Don't put discount in there if there isn't one
Else
strItemsOrdered = strItemsOrdered & "Discount : " &
CRS1.Fields("Discount") & "%" & vbCrLf
End If
strItemsOrdered = strItemsOrdered & "Total (Inc VAT): " & Chr(163)
& Format(CRS1.Fields("TotalIncVAT"), "##0.00") & vbCrLf & vbCrLf
CRS1.MoveNext
Wend
CRS1.Close
Set CRS1 = Nothing
Some of the MVPs have ESP, but for most everyone else it would be
helpful if you provided a clue as to what you mean by "it does not work."

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Aug 13 '06 #2
If you set the options to "Break on All Errors," then it would highlight the
offending line, and stop, so you could copy the content of the error message
to help us help you.

Larry Linson
Microsoft Access MVP

"Simon" <S.*******@shos.co.ukwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Can any one see a problem with this code ( it does not work

Private Sub cmdEmailOrderPlaced_Click()
'On Error GoTo Error_Handler
Dim strTo As String
Dim strBody As String
Dim strSubject As String
Dim strItemsOrdered As String
Dim CRS1 As ADODB.Recordset
Dim strSql As String
Set CRS1 = New ADODB.Recordset

sstrSql = "SELECT * FROM tblOrderProduct WHERE OrderNumber =" &
Me.OrderNumber
CRS1.Open strSql, CurrentProject.Connection, adOpenKeyset,
adLockReadOnly
While Not CRS1.EOF

strItemsOrdered = strItemsOrdered & "Item : " &
DLookup("[ProductName]", "tblProduct", "[ProductCode] =" &
CRS1.Fields("ProductCode"))

strItemsOrdered = strItemsOrdered & "Unit Price : " & Chr(163) &
DLookup("[PriceIncVAT ]", "tblProduct", "[ProductID] =" &
CRS1.Fields("ProductID")) & vbCrLf

'& vbCrLf & "Total Excl VAT: " & Chr(163) &
Format(CRS1.Fields("TotalExVAT"), "##0.00")

If IsNull(CRS1.Fields("Discount")) Or CRS1.Fields("Discount") = 0
Then
'Don't put discount in there if there isn't one
Else
strItemsOrdered = strItemsOrdered & "Discount : " &
CRS1.Fields("Discount") & "%" & vbCrLf
End If
strItemsOrdered = strItemsOrdered & "Total (Inc VAT): " & Chr(163)
& Format(CRS1.Fields("TotalIncVAT"), "##0.00") & vbCrLf & vbCrLf
CRS1.MoveNext
Wend
CRS1.Close
Set CRS1 = Nothing

Aug 13 '06 #3
The error line is
CRS1.Open strSql, CurrentProject.Connection, adOpenKeyset,
adLockReadOnly

Run time Error ' 2147217908(80040e0c)
Command text not set for the command object.

the code creats an email off the products my customer has bought.
The code us to work but I use to use Product ID with auto number for
each product i had, but then i changed it to 'Product Code' where i
type in my own code instead of auto number, i then changed the code
from Product ID to 'Product Code' and it does not work any more

Simon
Larry Linson wrote:
If you set the options to "Break on All Errors," then it would highlight the
offending line, and stop, so you could copy the content of the error message
to help us help you.

Larry Linson
Microsoft Access MVP

"Simon" <S.*******@shos.co.ukwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Can any one see a problem with this code ( it does not work

Private Sub cmdEmailOrderPlaced_Click()
'On Error GoTo Error_Handler
Dim strTo As String
Dim strBody As String
Dim strSubject As String
Dim strItemsOrdered As String
Dim CRS1 As ADODB.Recordset
Dim strSql As String
Set CRS1 = New ADODB.Recordset

sstrSql = "SELECT * FROM tblOrderProduct WHERE OrderNumber =" &
Me.OrderNumber
CRS1.Open strSql, CurrentProject.Connection, adOpenKeyset,
adLockReadOnly
While Not CRS1.EOF

strItemsOrdered = strItemsOrdered & "Item : " &
DLookup("[ProductName]", "tblProduct", "[ProductCode] =" &
CRS1.Fields("ProductCode"))

strItemsOrdered = strItemsOrdered & "Unit Price : " & Chr(163) &
DLookup("[PriceIncVAT ]", "tblProduct", "[ProductID] =" &
CRS1.Fields("ProductID")) & vbCrLf

'& vbCrLf & "Total Excl VAT: " & Chr(163) &
Format(CRS1.Fields("TotalExVAT"), "##0.00")

If IsNull(CRS1.Fields("Discount")) Or CRS1.Fields("Discount") = 0
Then
'Don't put discount in there if there isn't one
Else
strItemsOrdered = strItemsOrdered & "Discount : " &
CRS1.Fields("Discount") & "%" & vbCrLf
End If
strItemsOrdered = strItemsOrdered & "Total (Inc VAT): " & Chr(163)
& Format(CRS1.Fields("TotalIncVAT"), "##0.00") & vbCrLf & vbCrLf
CRS1.MoveNext
Wend
CRS1.Close
Set CRS1 = Nothing
Aug 13 '06 #4

I don't suppose ProductCode is a text field by any chance. If so you
need to alter the following line, like this:-

DLookup("[ProductName]", "tblProduct", "[ProductCode] ='" &
CRS1.Fields("ProductCode") & "'")

If it's not clear on the screen, what you have in front of the first
ampersand is a single quote mark followed by a double quote mark, and
at the end is a double - single - double

HTH
Dave

Aug 13 '06 #5
* Simon:
The error line is
CRS1.Open strSql, CurrentProject.Connection, adOpenKeyset,
adLockReadOnly

Run time Error ' 2147217908(80040e0c)
Command text not set for the command object.

the code creats an email off the products my customer has bought.
The code us to work but I use to use Product ID with auto number for
each product i had, but then i changed it to 'Product Code' where i
type in my own code instead of auto number, i then changed the code
from Product ID to 'Product Code' and it does not work any more

Simon
Larry Linson wrote:
>If you set the options to "Break on All Errors," then it would highlight the
offending line, and stop, so you could copy the content of the error message
to help us help you.

Larry Linson
Microsoft Access MVP

"Simon" <S.*******@shos.co.ukwrote in message
news:11**********************@b28g2000cwb.googleg roups.com...
>>Can any one see a problem with this code ( it does not work

Private Sub cmdEmailOrderPlaced_Click()
'On Error GoTo Error_Handler
Dim strTo As String
Dim strBody As String
Dim strSubject As String
Dim strItemsOrdered As String
Dim CRS1 As ADODB.Recordset
Dim strSql As String
Set CRS1 = New ADODB.Recordset

sstrSql = "SELECT * FROM tblOrderProduct WHERE OrderNumber =" &
Me.OrderNumber
CRS1.Open strSql, CurrentProject.Connection, adOpenKeyset,
adLockReadOnly
While Not CRS1.EOF

strItemsOrdered = strItemsOrdered & "Item : " &
DLookup("[ProductName]", "tblProduct", "[ProductCode] =" &
CRS1.Fields("ProductCode"))

strItemsOrdered = strItemsOrdered & "Unit Price : " & Chr(163) &
DLookup("[PriceIncVAT ]", "tblProduct", "[ProductID] =" &
CRS1.Fields("ProductID")) & vbCrLf

'& vbCrLf & "Total Excl VAT: " & Chr(163) &
Format(CRS1.Fields("TotalExVAT"), "##0.00")

If IsNull(CRS1.Fields("Discount")) Or CRS1.Fields("Discount") = 0
Then
'Don't put discount in there if there isn't one
Else
strItemsOrdered = strItemsOrdered & "Discount : " &
CRS1.Fields("Discount") & "%" & vbCrLf
End If
strItemsOrdered = strItemsOrdered & "Total (Inc VAT): " & Chr(163)
& Format(CRS1.Fields("TotalIncVAT"), "##0.00") & vbCrLf & vbCrLf
CRS1.MoveNext
Wend
CRS1.Close
Set CRS1 = Nothing
I don't know if you used copy/paste to post the message, but per the
code that was posted, you are not setting a value for strSql. The
assignment is for sstrSql. That would account for the error that you are
getting.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Aug 13 '06 #6
.... do you have Option Explicit in the declarations section of your module?
If not, put it there and at the top of all your modules. Then from the VBA
IDE go to Tools/Options and tick the "Require Variable Declaration" option,
this is off by default (Microsofts stupid make it easy to make a mess of
things) but should be the first thing you switch on whenever you install
Access.

--

Terry Kreft
"Randy Harris" <pl****@send.no.spamwrote in message
news:dP***************@newssvr13.news.prodigy.com. ..
* Simon:
The error line is
CRS1.Open strSql, CurrentProject.Connection, adOpenKeyset,
adLockReadOnly

Run time Error ' 2147217908(80040e0c)
Command text not set for the command object.

the code creats an email off the products my customer has bought.
The code us to work but I use to use Product ID with auto number for
each product i had, but then i changed it to 'Product Code' where i
type in my own code instead of auto number, i then changed the code
from Product ID to 'Product Code' and it does not work any more

Simon
Larry Linson wrote:
If you set the options to "Break on All Errors," then it would
highlight the
offending line, and stop, so you could copy the content of the error
message
to help us help you.

Larry Linson
Microsoft Access MVP

"Simon" <S.*******@shos.co.ukwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Can any one see a problem with this code ( it does not work

Private Sub cmdEmailOrderPlaced_Click()
'On Error GoTo Error_Handler
Dim strTo As String
Dim strBody As String
Dim strSubject As String
Dim strItemsOrdered As String
Dim CRS1 As ADODB.Recordset
Dim strSql As String
Set CRS1 = New ADODB.Recordset

sstrSql = "SELECT * FROM tblOrderProduct WHERE OrderNumber =" &
Me.OrderNumber
CRS1.Open strSql, CurrentProject.Connection, adOpenKeyset,
adLockReadOnly
While Not CRS1.EOF

strItemsOrdered = strItemsOrdered & "Item : " &
DLookup("[ProductName]", "tblProduct", "[ProductCode] =" &
CRS1.Fields("ProductCode"))

strItemsOrdered = strItemsOrdered & "Unit Price : " & Chr(163) &
DLookup("[PriceIncVAT ]", "tblProduct", "[ProductID] =" &
CRS1.Fields("ProductID")) & vbCrLf

'& vbCrLf & "Total Excl VAT: " & Chr(163) &
Format(CRS1.Fields("TotalExVAT"), "##0.00")

If IsNull(CRS1.Fields("Discount")) Or CRS1.Fields("Discount") = 0
Then
'Don't put discount in there if there isn't one
Else
strItemsOrdered = strItemsOrdered & "Discount : " &
CRS1.Fields("Discount") & "%" & vbCrLf
End If
strItemsOrdered = strItemsOrdered & "Total (Inc VAT): " & Chr(163)
& Format(CRS1.Fields("TotalIncVAT"), "##0.00") & vbCrLf & vbCrLf
CRS1.MoveNext
Wend
CRS1.Close
Set CRS1 = Nothing

I don't know if you used copy/paste to post the message, but per the
code that was posted, you are not setting a value for strSql. The
assignment is for sstrSql. That would account for the error that you are
getting.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.

Aug 13 '06 #7
"Terry Kreft" <te*********@mps.co.ukwrote in
news:4B********************@karoo.co.uk:
... do you have Option Explicit in the declarations section of
your module? If not, put it there and at the top of all your
modules. Then from the VBA IDE go to Tools/Options and tick the
"Require Variable Declaration" option, this is off by default
(Microsofts stupid make it easy to make a mess of things) but
should be the first thing you switch on whenever you install
Access.
Actually, it was Microsoft's stupid decision to make the Access VBE
consistent with VBE in all the other office apps because,
er, um, well, because consistency is a value all by itself, even
though fewer than .05% of those who code in Access are coming to
Access from coding in Excel or Word.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Aug 14 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
8
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
8
by: Steve Jorgensen | last post by:
Hi folks, I'm posting this message because it's an issue I come up against relatively often, but I can't find any writings on the subject, and I haven't been able to figure out even what key...
2
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
8
by: Andy B | last post by:
Before I do a no no on a newsgroup, I need to ask a question: What is the max number of lines of code you can/should post here before it gets too long?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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
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,...
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,...

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.