Results 1 to 5 of 5

Thread: Database Access Problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Posts
    14

    Post

    I designed an inventory program to keep track of parts out of a database. I had it working great and used this code to call up the part when the item number box lost focus. Now every time I put in a number the program stops. I changed some of the references that are in the VB5 compiler and I think that may have something to do with it, the code is below. Any help would be greatly appreciated.


    Private Sub txtNum_LostFocus()

    Dim dbs As Database
    Dim inventory As Recordset
    Dim wrkDefault As Workspace
    Dim temp As Integer
    Dim counter As Integer


    Set wrkDefault = DBEngine.Workspaces(0)
    Set dbs = OpenDatabase("parts.mdb")
    Set inventory = _
    dbs.OpenRecordset("Inventory", dbOpenDynaset)

    OrderByX

    Do
    If txtNum.Text = inventory!Itemnumber Then

    txtNum.Text = inventory!Itemnumber
    txtDesc.Text = inventory!Description
    txtRetail.Text = inventory!Retail
    txtWhole.Text = inventory!Wholesale
    txtProfit.Text = inventory!Profit
    cmbCompany.Text = inventory!Company
    txtQty.Text = inventory!Qty
    txtMemo.Text = inventory!MemoBox
    counter = counter + 1
    Else

    inventory.MoveNext

    End If

    Loop While inventory!Itemnumber <> 1

    End Sub

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    What do you mean by "the program stops"? Does it end, or does it go into a loop?

    What does OrderByX do?
    What is Counter for?

    This is not part of your problem but you should put the opening of the database in some other routine and do it just once, rather than every time the textbox loses focus. You should also make sure to set inventory = Nothing in the LoatFocus event and to close the database someplace. Also, the txtNum.Text = inventory!Itemnumber line is not necessary.

    ------------------
    Marty
    HASTE CUISINE
    Fast French food.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Posts
    14

    Post

    The orderbyx sub takes the database and orders the database according to item number. This is because the I have a flag set in the database. The counter was from another attempt at the database. Also, the programs gets stuck in a loop. But it shouldn't because the code looks right and it worked a day ago and I didn't change the code. Thanks.

  4. #4
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    I think you need to check for EOF in your do loop, otherwise it's gonna go infinite _if_ the last record's Itemnumber retrieved is some number other than 1.

    [This message has been edited by JHausmann (edited 02-03-2000).]

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Posts
    14

    Post

    I just wanted to say thank you. The EOF thing worked. I just had it exit the do loop then. The more I think of it I DID have code like that in but I have no idea what happened. I knew it had worked before.

    Thanks again!

    Jeremy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width