Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Emma G is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    13

    Is it possible for a message box to display a single record from a QBA query from a form?

    Hello,

    I am currently constructing a library database. I have a 'Check in' form where the user enters the 'barcode number' of a book into the form and clicks a 'submit' button which runs a query that uses that data to locate and delete the record from the 'On Loan' table. That all works fine. I have currently designed it so that once the user clicks the 'submit' button the query will run and a message box will appear displaying the same message 'Check in was successful'. This chain of events was created using macros.

    My question is...is there a way of getting the message box to display the patron that Checked In the book in the first place instead i.e. 'Thank you [patron name] your book has been successfully checked in'. The name of the patron would be in the 'On Loan' table under the same record that the other query I mentioned would use. It would obviously need to display a different name each time. I imagine I would need to use a query to do this. Is there away this could be achieved? I feel that it would greatly improve the user interface of my library database if so.

    Many thanks,



    Emma

  2. #2
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    Emma,

    You can do that. First I would convert your macros to code. but you can add this to your code and it will give you the message you are wanting

    Code:
    MsgBox "Thank you " & (UserName) & vbCrLf & "Book successfully returned."
    UserName being where the patrons name is stored if it is a txt box

  3. #3
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,819
    If you delete the record first, the name is gone. If you show the message then the delete fails for any reason, the book is still OnLoan even though it has been checked in. Consider flagging the record instead of deleting. Not sure if you have another means of tracking loans, but this would also allow you to report on patron loan frequency, loan counts on any given book, or anything else you can think of.
    EDIT
    A query or DLookup can do what you want. You've posted in the Forms part of the form, so I imagine you have one to work from as was assumed. However, if you have more than one copy of a book, how are you tying the returned copy to Mr. Smith instead of anyone else who has borrowed one?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Emma G is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    13
    Quote Originally Posted by NightWalker View Post
    Emma,

    You can do that. First I would convert your macros to code. but you can add this to your code and it will give you the message you are wanting

    Code:
    MsgBox "Thank you " & (UserName) & vbCrLf & "Book successfully returned."
    UserName being where the patrons name is stored if it is a txt box
    Thank you NightWalker. I will give that a go!

  5. #5
    Emma G is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    13
    Quote Originally Posted by Micron View Post
    If you delete the record first, the name is gone. If you show the message then the delete fails for any reason, the book is still OnLoan even though it has been checked in. Consider flagging the record instead of deleting. Not sure if you have another means of tracking loans, but this would also allow you to report on patron loan frequency, loan counts on any given book, or anything else you can think of.
    EDIT
    A query or DLookup can do what you want. You've posted in the Forms part of the form, so I imagine you have one to work from as was assumed. However, if you have more than one copy of a book, how are you tying the returned copy to Mr. Smith instead of anyone else who has borrowed one?
    Currently I am appending the record to a 'Loan History' table before deleting it. In regards to having more than one copy of a book I was planning on giving each book an individual barcode sticker, unless you can think of an easier way?

    Please coud you explain how to flag a record.

    Many thanks,

    Emma

  6. #6
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,819
    Individual bar code would be a good method. To flag a record, you need a field whose value you can set appropriately. In your case, a Yes/No field that you set to True when the book is returned. Or a text field that you set to "True" or any appropriate text value. Or a numeric field that you set to 0 or 1 (least preferred for your situation, IMO). At this point, I'm not seeing how you grab the correct name if you don't have the bar code yet.
    Another afterthought:
    Don't mean to be critical, but if you're moving records around to accomplish this history, it sounds like you have db design issues. It's not a good idea to move records like this. You can get your history and status by querying the OnLoan table, especially if it has a returned flag. You say you have the patron name in the OnLoan table also? That would be poor design choice, I'm afraid.

  7. #7
    Emma G is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    13
    Quote Originally Posted by Micron View Post
    Individual bar code would be a good method. To flag a record, you need a field whose value you can set appropriately. In your case, a Yes/No field that you set to True when the book is returned. Or a text field that you set to "True" or any appropriate text value. Or a numeric field that you set to 0 or 1 (least preferred for your situation, IMO). At this point, I'm not seeing how you grab the correct name if you don't have the bar code yet.
    Another afterthought:
    Don't mean to be critical, but if you're moving records around to accomplish this history, it sounds like you have db design issues. It's not a good idea to move records like this. You can get your history and status by querying the OnLoan table, especially if it has a returned flag. You say you have the patron name in the OnLoan table also? That would be poor design choice, I'm afraid.
    I have test barcode values that I am using. Thank you for explaining how to flag a record. I understand how you mean and how to change the yes/no field but im not sure how you could use this to track how many loans a book has had etc. as you mentioned in your earlier post?

  8. #8
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,819
    You wouldn't. For that you would count the records per book. The flag was to tell you it had been returned without moving the record. You could also count how many were in versus out. Still thinking you have design issues though.

  9. #9
    Emma G is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    13
    Quote Originally Posted by Micron View Post
    You wouldn't. For that you would count the records per book. The flag was to tell you it had been returned without moving the record. You could also count how many were in versus out. Still thinking you have design issues though.
    By design issues are you referring the append and delete query sequence and think the yes/no box change would be better?

  10. #10
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,819
    No, I get the impression you have patron names in a loan table because you were going to get the name from it for your message box. Plus, you are/were moving records around. Kinda raises red flags for me. Suggest you go here
    http://www.databaseanswers.org/data_models/
    and see if any of it makes sense and resembles what you are doing. There is a db model section for a library.
    If it raises any flags for you, maybe start a new thread pertaining to db design since that would not be related to your original post.
    Last edited by Micron; 06-03-2016 at 03:39 PM. Reason: forgot link

  11. #11
    Emma G is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    13
    Thank you Micron for all of your advice and for the link.

    Have a great weekend.

    Emma

  12. #12
    Emma G is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    13
    Quote Originally Posted by NightWalker View Post
    Emma,

    You can do that. First I would convert your macros to code. but you can add this to your code and it will give you the message you are wanting

    Code:
    MsgBox "Thank you " & (UserName) & vbCrLf & "Book successfully returned."
    UserName being where the patrons name is stored if it is a txt box

    Sorry NightWalker, could I ask a little bit of further advice. My ´Check In´ forms runs by a patron typing/scanning the barcode number of the book into the ´Barcode Number´ text box. The forms then uses this information in the query ´qryCheckIn´ that locates the record including the ´Forename´ and ´Surname´ from the ´On Loan´ table and then appends it to a table called ´Loan History´ using the ´qryCheckInAppend´. There is no actual text box on the form that contains the patrons name.

    I have converted the Macros in this form to VB as you suggested. However, as I am new to coding I am unsure how to refer to the ´Forename´ and ´Surname´ fields in that line of code you supplied in order for it to be used in the message box to display the name of the patron who borrowed that particular book. How would I do that?

    Many thanks.

    Emma

  13. #13
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    Emma,

    I will try to get back to you with in the next day or two. If someone else gets to it first that would be great but I will have limited access to my computer for the next couple days.

    I will reply as soon as I can.

    Sorry,
    Walker

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    It might help to see your code, but if it's only in the query and that query returns a single record, then you could do:

    Dim strUserName as String
    strUserName = Dlookup("Forename", "qryCheckIn")
    MsgBox "Thank you " & strUserName & vbCrLf & "Book successfully returned."
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Without seeing the code or the SQL of the queries, there are a couple of ways to go:

    In the check-in code, you would open a recordset on "qryCheckIn" (if the query is a select query) and

    A) set two variables to the "Forename" and "Surname" value
    Code:
    sFName = r!Forename
    sSName = r!Surname
    sMsg = "Thank you " & sFName & " " & sSName & vbCrLf & "Book successfully returned."
    Msgbox sMsg
    OR

    B) by construct a string something like
    Code:
    sMsg = "Thank you " & r!Forename & " " & r!Surname & vbCrLf & "Book successfully returned."
    Msgbox sMsg
    It would really help if you post the code and the SQL of the two queries (qryCheckIn & qryCheckInAppend)

    BTW, I would have to agree with Micron about your table structure probably needs work.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 08-02-2015, 12:42 AM
  2. single query row display multiple subrecords?
    By vientito in forum Queries
    Replies: 1
    Last Post: 10-21-2014, 06:20 AM
  3. Replies: 1
    Last Post: 07-03-2014, 08:27 PM
  4. Single Record Update Query from a Form
    By Steven.Allman in forum Access
    Replies: 0
    Last Post: 03-30-2011, 09:34 AM
  5. Query to display in single row
    By access in forum Queries
    Replies: 10
    Last Post: 01-14-2010, 11:40 AM

Tags for this Thread

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