Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I get a value from a SQL statement into a recordset?

Posted on 2005-05-12
3
Medium Priority
?
171 Views
Last Modified: 2011-09-20
   Dim rsIB, countIBGroup
    countIBGroup = 1
       
    Set CMD.ActiveConnection = Conn
This is my code, but it doesn't work.  Even though my SQL statement should give me the value in the LOOKUP_ORDER field, but
when I debug my code, I don't get any value into the rsIB variable
The LOOKUP_ORDER field is a numeric field, it should give me the highest number in that field, but it doesn't...  
Can you help?

    CMD.CommandText = "SELECT TOP 1 LOOKUP_ORDER FROM LOOKUP_VALUES WHERE LOOKUP_NAME like 'IB_GROUP%' ORDER BY LOOKUP_ORDER DESC"
    CMD.CommandType = adCmdText
   
    'DMG (AH) -- Increment the highest LOOKUP_CODE value by one, so the new IB_GROUP records added to LOOKUP_VALUES are UNIQUE
    Set rsIB = CMD.Execute
         
    countIBGroup = IIf(IsNull(rsIB), 1, rsIB + 1)

    CMD.CommandText = "Insert Into LOOKUP_VALUES (LOOKUP_NAME, LOOKUP_CODE, LOOKUP_DESC, LOOKUP_ORDER) Values('IB_GROUP', '" & CStr(countIBGroup) & "', '" & Replace(txtAddIBGroup.Text, "'", "''") & "',  '" & CStr(countIBGroup) & "')"
       
    Call AddAudit("FormAdminIBGroup", CMD.CommandText)
   
   
0
Comment
Question by:angelahontau
  • 2
3 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 13993025
try this:

countIBGroup = IIf(IsNull(rsIB.Fields(0).Value), 1,rsIB.Fields(0).Value+ 1)

AW
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 2000 total points
ID: 13993035
also:

  CMD.CommandText = "SELECT TOP 1 LOOKUP_ORDER FROM LOOKUP_VALUES WHERE LOOKUP_NAME like 'IB_GROUP%' ORDER BY LOOKUP_ORDER DESC"
    CMD.CommandType = adCmdText
   
    'DMG (AH) -- Increment the highest LOOKUP_CODE value by one, so the new IB_GROUP records added to LOOKUP_VALUES are UNIQUE
    Set rsIB = CMD.Execute
    if not rsIB.EOF then
         countIBGroup = IIf(IsNull(rsIB.fields(0).Value), 1, rsIB.Fields(0).Value + 1)
        CMD.CommandText = "Insert Into LOOKUP_VALUES (LOOKUP_NAME, LOOKUP_CODE, LOOKUP_DESC, LOOKUP_ORDER) Values('IB_GROUP', '" & CStr(countIBGroup) & "', '" & Replace(txtAddIBGroup.Text, "'", "''") & "',  '" & CStr(countIBGroup) & "')"
        cmd.Execute

         Call AddAudit("FormAdminIBGroup", CMD.CommandText)

    else
         MsgBox "There were no values returned". VBOkOnly
    end if

AW

0
 

Author Comment

by:angelahontau
ID: 13993102
THANK YOU SO MUCH!  I ASKED THIS QUESTION BEFORE AND ON ONE COULD HELP  :(
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question