Results 1 to 7 of 7
  1. #1
    USFStudent is offline Novice
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    3

    Looking for help with programming a button

    I am new to using code and am looking for help. Below is what I am stuck on. I need to make it so if the library item is checked out it will show a message "checked out" and if not it will continue on so I can write the rest of the code. I dont know how to target "checked out" from the tblLibraryItem("Status") the right way. Any input would be great and I can post the rest of the code if it helps.





    Loop


    If rstLibraryItem("Status") = "Checked Out" Then
    MsgBox " " & rstLibraryItem("Status")
    Else
    MsgBox "" & rstLibraryItem("Status")

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    rest of the code would be helpful plus a clearer explanation on what 'stuck on' means - you get errors? code doesn't work as expected?

  3. #3
    USFStudent is offline Novice
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    3
    I want to make sure that the msgbox works for when the book is checked out and if not it will continue on to where I can add more code to update the table. I would then get rid of the second msgbox that is there. I wanted to make sure it works before I went on. I have "In Stock" and "Checked Out" as the status.

    Private Sub btnCheckout_Click()
    Dim ItemToCheckout As String
    Dim MemberIDToCheckout As String


    cboItemToCheckout.SetFocus
    If cboItemToCheckout.Text = "" Then
    MsgBox "Please select Item Name"
    Exit Sub
    End If
    ItemToCheckout = cboItemToCheckout.Text


    cboMemberIDToCheckout.SetFocus
    If cboMemberIDToCheckout.Text = "" Then
    MsgBox "Please select Member"
    Exit Sub
    End If
    MemberIDToCheckout = cboMemberIDToCheckout.Text


    Dim TodaysDate As Date
    TodaysDate = Date


    Dim currDatabase As DAO.Database
    Set currDatabase = CurrentDb


    Dim rstLibraryItem As DAO.Recordset
    Set rstLibraryItem = currDatabase.OpenRecordset("tblLibraryItem")


    rstLibraryItem.MoveFirst
    Do While Not rstLibraryItem.EOF
    If rstLibraryItem("ItemID") = ItemToCheckout Then Exit Do
    rstLibraryItem.MoveNext

    Loop


    If rstLibraryItem("Status") = "Checked Out" Then
    MsgBox " " & rstLibraryItem("Status")
    Else
    MsgBox "" & rstLibraryItem("Status")





    End Sub

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    What exactly do you think this code does?
    Code:
    If rstLibraryItem("Status") = "Checked Out" Then
       MsgBox " " & rstLibraryItem("Status")
    Else
       MsgBox "" & rstLibraryItem("Status")

    Seems it says,

    Code:
    If the status of this book is "CheckedOut" then
        Display "A message"
    Else (if it is not "CheckedOut")
         Display the same message
    End If
    that isn't what you want.

    Figure out your logic, in plain English, before you start coding. From experience, coding while you're still trying to figure out what you are trying to do, is a strategy for frustration.

    Code:
    If BookCheckedOut is True
        do process to inform user book is not available
    Else
        do process to check out this book for this user
    End

  5. #5
    USFStudent is offline Novice
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    3
    If rstLibraryItem("Status") = "Checked Out" Then
    MsgBox "Checked Out"
    Else
    MsgBox "Can Check Out Item"

    This is what I want but The first line is where I dont know if there is something else I need to put in to know if it is checked out or if I can proceed to checking out the book.

  6. #6
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Well what other things were you thinking of?

    The logic depends on the value of the Status field.If the Status field is NOT updated properly (time delay, bad process....), then perhaps you can't depend only on the Status field value. And, if there are other conditions, you will have to check those.

  7. #7
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    looks like you are trying to use a sequential search for an item and not making use of indexing.

    Also things like

    cboMemberIDToCheckout.SetFocus
    If cboMemberIDToCheckout.Text = "" Then
    can simply be

    If cboMemberIDToCheckout= "" Then
    and this won't work

    MemberIDToCheckout = cboMemberIDToCheckout.Text
    since text only works if the control has the focus. All you need if

    MemberIDToCheckout = cboMemberIDToCheckout
    but then, having assigned it, you don't do anything with it

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

Similar Threads

  1. Replies: 4
    Last Post: 05-29-2015, 09:36 AM
  2. Replies: 30
    Last Post: 09-27-2013, 01:34 PM
  3. Programming of 'SAVE' button in Access 2010
    By THE STUDENT in forum Access
    Replies: 5
    Last Post: 06-07-2013, 01:23 PM
  4. Replies: 1
    Last Post: 12-19-2012, 08:09 PM
  5. programming button to update records
    By lstairs in forum Programming
    Replies: 5
    Last Post: 02-04-2010, 08:07 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