473,498 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Urgent

123 New Member
I have written a query sql = "SELECT Max(No) FROM Temp" in recordset using
rs.open sql,cn,,,adcmdText. How to fetch the result of a recordet. I get wrong answer when i execute following code:

Expand|Select|Wrap|Line Numbers
  1. Dim i as Long
  2.  
  3. sql = ""SELECT Max(No) FROM Temp""
  4. rs.open sql, cn,,,adcmdText
  5. i = rs(0)
  6. MsgBox(i)
Answer i get is 0 but it should come 4.

Plz tell me correct code
Feb 22 '07 #1
13 1349
vijaydiwakar
579 Contributor
I have written a query sql = "SELECT Max(No) FROM Temp" in recordset using
rs.open sql,cn,,,adcmdText. How to fetch the result of a recordet. I get wrong answer when i execute following code:

Dim i as Long

sql = ""SELECT Max(No) FROM Temp""
rs.open sql, cn,,,adcmdText
i = rs(0)
MsgBox(i)

Answer i get is 0 but it should come 4.

Plz tell me correct code
Hi, Shailaja
Try this
Select nvl(max(no),0) from temp -> if ur using oracle
try to use adcmdDynamic
Feb 22 '07 #2
Shailja
123 New Member
Hi, Shailaja
Try this
Select nvl(max(no),0) from temp -> if ur using oracle
try to use adcmdDynamic
I
I am not using ORACLE, My Back End is Access.
Feb 22 '07 #3
hariharanmca
1,977 Top Contributor
I
I am not using ORACLE, My Back End is Access.

Expand|Select|Wrap|Line Numbers
  1. sql = ""SELECT Max(No) FROM Temp""
  2. rs.open sql, cn,,,adcmdText
  3. i = rs(0)
  4. MsgBox(i)
  5.  
  6. for access qry is correct,... Ok just try this
  7.  
  8. sql = ""SELECT Max(No) FROM Temp""
  9. rs.open sql, cn,,,adcmdText
  10. i = rs.field(0)
  11. or
  12. i = rs.field(0).value
  13. MsgBox(i)
Feb 22 '07 #4
vijaydiwakar
579 Contributor
I
I am not using ORACLE, My Back End is Access.
Would u pls give me the tbl structure along with some data and the version of msaccess
Feb 22 '07 #5
Shailja
123 New Member
Would u pls give me the tbl structure along with some data and the version of msaccess
Table: Temp

No Name
1 A
2 B
3 C
Feb 22 '07 #6
Shailja
123 New Member
sql = ""SELECT Max(No) FROM Temp""
rs.open sql, cn,,,adcmdText
i = rs(0)
MsgBox(i)

for access qry is correct,... Ok just try this

sql = ""SELECT Max(No) FROM Temp""
rs.open sql, cn,,,adcmdText
i = rs.field(0)
or
i = rs.field(0).value
MsgBox(i)
I have tried both the above code , u have given. But still getting 0 answer.
Feb 22 '07 #7
vijaydiwakar
579 Contributor
Table: Temp

No Name
1 A
2 B
3 C
Shailaja there are so many problems in msaccess, ur facing one of them right now
the sol is just change the column name from no to myno or what evr u like
and run the qry
alsom change the name field name if u will use date then donot use ddate or date as column name
by
Feb 22 '07 #8
Killer42
8,435 Recognized Expert Expert
Personally, I think the problem might be the extra quotes around the SQL. To quote your original code...
Expand|Select|Wrap|Line Numbers
  1. Dim i as Long
  2.  
  3. sql = ""SELECT Max(No) FROM Temp""
  4. rs.open sql, cn,,,adcmdText
  5. i = rs(0)
  6. MsgBox(i)
What about trying this...
Expand|Select|Wrap|Line Numbers
  1. Dim i as Long
  2.  
  3. sql = "SELECT Max(No) FROM Temp;"
  4. rs.open sql, cn,,,adcmdText
  5. i = rs(0)
  6. MsgBox(i)
Feb 22 '07 #9
vijaydiwakar
579 Contributor
Personally, I think the problem might be the extra quotes around the SQL. To quote your original code...
Expand|Select|Wrap|Line Numbers
  1. Dim i as Long
  2.  
  3. sql = ""SELECT Max(No) FROM Temp""
  4. rs.open sql, cn,,,adcmdText
  5. i = rs(0)
  6. MsgBox(i)
What about trying this...
Expand|Select|Wrap|Line Numbers
  1. Dim i as Long
  2.  
  3. sql = "SELECT Max(No) FROM Temp;"
  4. rs.open sql, cn,,,adcmdText
  5. i = rs(0)
  6. MsgBox(i)
No Boss the problem will be get solved by the suggetion i'v given just try it out
bye
Feb 22 '07 #10
Killer42
8,435 Recognized Expert Expert
No Boss the problem will be get solved by the suggetion i'v given just try it out
No, pick me! :D

Seriously, though. Are you thinking fieldname "No" is being interpreted in the context of Yes/No? Have to watch those reserved words, huh.
Feb 22 '07 #11
hariharanmca
1,977 Top Contributor
No, pick me! :D

Seriously, though. Are you thinking fieldname "No" is being interpreted in the context of Yes/No? Have to watch those reserved words, huh.
Yes in MS Access 'No' is reserved word, just we have to try some other
Feb 22 '07 #12
vijaydiwakar
579 Contributor
No, pick me! :D

Seriously, though. Are you thinking fieldname "No" is being interpreted in the context of Yes/No? Have to watch those reserved words, huh.
Just do the thing i sugested and u will get the ans itself :D
Feb 22 '07 #13
willakawill
1,646 Top Contributor
To avoid problems with reserved words in sql it is always good practise to write your statements out in full including square brackets, no shortcuts and no fingers crossed :)

Expand|Select|Wrap|Line Numbers
  1. Dim i As Long
  2. Dim sql As String
  3.  
  4. sql = "SELECT Max([Temp].[No]) AS MaxNo FROM [Temp]"
  5. rs.open sql, cn,,,adcmdText
  6. i = rs("MaxNo")
  7. MsgBox("The max no is: " & i, "Maximum Number")
Feb 22 '07 #14

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

Similar topics

3
2399
by: Rob | last post by:
I have a form - when you click the submit button, it appends a variable to the URL (e.g. xyz.cgi?inputID=some_dynamic_variable) It also opens a new page. Now, that some_dynamic_variable is...
9
4280
by: Stefan Bauer | last post by:
Hi NG, we've got a very urgent problem... :( We are importing data with the LOAD utility. The input DATE field data is in the format DDMMYYYY (for days) and MMYYYY (for months). The target...
8
5206
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
28
2998
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
16
2888
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
7
7223
by: zeyais | last post by:
Here is my HTML: <style> ..leftcolumn{float:left;width:300px;border: 1px solid #ccc} ..rtcolumn{float:left;width:600px;border: 1px solid #ccc} </style> <body> <div class="leftcolumn"...
33
3360
by: dembla | last post by:
Hey Frnds can anyone help me in this i need a program in 'c' PROGRAM to print NxN Matrix 9 1 8 1 2 3 2 7 3 as 4 5 6 6 4 5 7 8 9 in sorted form
8
2748
by: ginnisharma1 | last post by:
Hi All, I am very new to C language and I got really big assignment in my work.I am wondering if anyone can help me.........I need to port compiler from unix to windows and compiler is written...
3
6430
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
7
5941
by: Cirene | last post by:
I used to use the Web Deployment Project with my VS2005 projects. Now I've fully upgraded to VS2008. Do I have to download a new version of the Web Deployment Project? If so where can I find...
0
7125
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
7002
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...
1
6885
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...
1
4908
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...
0
4588
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...
0
3093
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...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
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 ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.