Results 1 to 6 of 6
  1. #1
    bimcompu is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    7

    Semi-Nube Simple DLookup Issue - Help?

    Hi guys - I have a simple problem that has been nagging me for days on end. Here goes, I hope I can explain it:



    I have a simple table called LastBatch - it has 2 fields and 3 records - field names are Type and BatchNum


    Type LastBatch
    NH 400
    LCD 345
    FS 012


    Type is a Two or three character name and the BatchNum is a 3 character number

    All I am trying to do is lookup the type and find the value of BatchNum, add 1 to it and write it back to BatchNum for the next use

    Example: FS is the type and BatchNum value is 012

    when I click a radio button in the form I want it to update the table so that the value of NH becomes 13

    I have gotten it to count without a problem but it always writes back to the first record in the table even though FS is record three

    Here is my code:

    Private Sub Option8_Click()
    Dim NewBatch
    Dim LastBatch1
    NewBatch = DLookup("[BatchNum]", "LastBatch", "[Type] = 'NH'")
    MsgBox NewBatch
    LastBatch1 = NewBatch + 1
    MsgBox LastBatch1
    End Sub

    Thanks for any suggestions in advance

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Why do you want this? Saving calculated data can be risky especially when there is no raw data to support the saved value. What if you accidentally repeatedly click the button?

    Options:

    1. move to the desired record on a form

    2. use sql UPDATE action to modify the record in table: CurrentDb.Execute "UPDATE LastBatch SET BatchNum=" & NewBatch & " WHERE Type='NH'"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    bimcompu is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    7
    Thank you for the quick responce. It is nice to know that there are people out there that still care about other people and their problems. Here is what I am trying to accomplish:

    I am the keeper of an inventory that has three departments. The database works fine and I have a form that automates most of the data entry for keeping tabs on all of the inventory. One of the fields in the main table is BatchNum.

    Certain items in our inventory are placed in batches so that I don't have to count them on a monthly basis I can just look up the batch number that I placed on the batch itself and see the quantities.

    What I am trying to accomplish is a running table of the last batch number and be able to increase that number by one every time I create a new batch. From there I export the data to a spreadsheet and create a batch ticket using merge in MS Word to place on the shelf with that batch.

    I have all of it working except for the updating of the batch number.

    I am going to try your suggestion when I get some time.

    Thanks again!

  4. #4
    bimcompu is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    7
    That suggestion worked perfectly!! Now one more thing: Is it possible to place a variable in place if the hard coded "FN"? I can make it work hard coded if I duplicate the code for every department or create a variable with a list box.

    I tried:

    using Whatever as the variable from the list box

    CurrentDb.Execute "UPDATE LastBatch SET BatchNum=" & NewBatch & " WHERE Type=" & whatever - Didn't work

    CurrentDb.Execute "UPDATE LastBatch SET BatchNum=" & NewBatch & " WHERE Type= whatever - Didn't work

    CurrentDb.Execute "UPDATE LastBatch SET BatchNum=" & NewBatch & " WHERE Type=" & [Whatever]

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Yes, can use a variable. How do you want to populate the variable? Have user select item from combo or list box? Then code can reference the listbox - the listbox is the variable.

    CurrentDb.Execute "UPDATE LastBatch SET BatchNum=" & NewBatch & " WHERE Type='" & Me.listboxname & "'"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    bimcompu is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    7
    Perfect! Thanks for the help. My batch program now works and is keeping tabs on everything! Thanks again!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. DLookup issue
    By Alex Motilal in forum Programming
    Replies: 7
    Last Post: 04-17-2013, 12:41 PM
  2. Help With Simple Error on Dlookup and Insert To
    By asdaf3814 in forum Programming
    Replies: 9
    Last Post: 08-09-2012, 10:50 AM
  3. Dlookup issue
    By brharrii in forum Programming
    Replies: 3
    Last Post: 06-22-2012, 07:08 PM
  4. DLookup issue
    By seth1685 in forum Programming
    Replies: 5
    Last Post: 01-12-2012, 08:55 AM
  5. Simple issue?
    By Patience in forum Access
    Replies: 8
    Last Post: 05-29-2010, 07:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums