Results 1 to 7 of 7
  1. #1
    Oblivion_Creed is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2017
    Posts
    20

    a form works wierd

    Hello, my project is big (over 10mb) so i uploaded it to drive: https://drive.google.com/file/d/1VA4...ew?usp=sharing

    In the form "frmBorrow" there is a button with a macro.

    in that macro there's this condition:
    ElseIf (DLookup("[LibraryID]", "tblCurrentUser") - DLookup("[libraryID]", "tblBooks") = 0) Then
    Beep


    MsgBox "The given book dosen't exist in YOUR library", vbOKOnly, "error"

    i ment in here to check if the book is in the same library as the user but it doesn't work.

    can any one help me fix it?

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    What do you mean by does not work, does it give error or does not return data?

    I think you need the where part of DLookup or how does it know which record and LIbraryID to choose? Maybe:
    (DLookup("[LibraryID]", "tblCurrentUser", "LibraryID = " & CurrentLibraryID) - DLookup("[libraryID]", "tblBooks", "LibraryID = " & CurrentLibraryID) = 0)

    CurrentLibraryID might be from your recordset or value on form, etc. I just named it that but you need to put right name and syntax there.

  3. #3
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Macros are cumbersome and restrictive. Click on the Convert to VBA button, it will be easier to read and to troubleshoot.

  4. #4
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    ElseIf DLookup("[LibraryID]", "tblCurrentUser") <> DLookup("[libraryID]", "tblBooks") Then
    Without the criteria part, DLookup will stop at the first record where the field is not null (unless I'm wrong about that and it will stop at the first record - period).
    Aside from that, the expression posted basically says, if LibraryID in table A minus LibraryID in table B = 0, then do what follows because it's true. If the id's are text, then unless they can be treated as numbers, you're trying to subtract 2 words from each other. If the id's are autonumbers, you shouldn't be trying to do anything with them. If they are numbers, then just compare them instead of doing arithmetic on them.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Oblivion_Creed is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2017
    Posts
    20
    Quote Originally Posted by Bulzie View Post
    What do you mean by does not work, does it give error or does not return data?

    I think you need the where part of DLookup or how does it know which record and LIbraryID to choose? Maybe:
    (DLookup("[LibraryID]", "tblCurrentUser", "LibraryID = " & CurrentLibraryID) - DLookup("[libraryID]", "tblBooks", "LibraryID = " & CurrentLibraryID) = 0)

    CurrentLibraryID might be from your recordset or value on form, etc. I just named it that but you need to put right name and syntax there.
    Quote Originally Posted by aytee111 View Post
    Macros are cumbersome and restrictive. Click on the Convert to VBA button, it will be easier to read and to troubleshoot.
    Quote Originally Posted by Micron View Post
    ElseIf DLookup("[LibraryID]", "tblCurrentUser") <> DLookup("[libraryID]", "tblBooks") Then
    Without the criteria part, DLookup will stop at the first record where the field is not null (unless I'm wrong about that and it will stop at the first record - period).
    Aside from that, the expression posted basically says, if LibraryID in table A minus LibraryID in table B = 0, then do what follows because it's true. If the id's are text, then unless they can be treated as numbers, you're trying to subtract 2 words from each other. If the id's are autonumbers, you shouldn't be trying to do anything with them. If they are numbers, then just compare them instead of doing arithmetic on them.
    The code should check if the librarian who's trying to borrow the book is in the same library as the book...
    the code i tried using and your codes allowed the librarian borrow books from different library or didn't allow it to borrow book from and library

  6. #6
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I was trying to make the point that without where criteria your expression couldn't work regardless. If no one can help you soon I'll look at it further when I get home. Not going to try this on my phone.

  7. #7
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    In your db,
    LibraryID in tblLibraries is a number, like 1,2,3
    LibraryID in tblBooks and tblCurrentUser is a text field containing Arabic characters. It should be numeric, containing a value (1,2,3) equal to a key in tblLibraries.
    None of your user defined tables are set up in the relationship window. You need to get all of this straight before making queries or even forms or reports.
    Last edited by davegri; 11-28-2017 at 10:18 PM. Reason: clarif

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

Similar Threads

  1. Wierd resolution error
    By CHEECO in forum Access
    Replies: 1
    Last Post: 04-17-2016, 09:27 AM
  2. Wierd Characters in Field
    By RegVaz in forum Access
    Replies: 5
    Last Post: 01-17-2012, 01:46 PM
  3. Table/Query acting wierd
    By Rick West in forum Queries
    Replies: 2
    Last Post: 03-10-2010, 10:11 AM
  4. docmd.rename wierd results
    By hyperionfall in forum Programming
    Replies: 1
    Last Post: 03-04-2010, 01:18 PM
  5. Wierd subdatasheet problem
    By Lynnwood in forum Access
    Replies: 0
    Last Post: 10-30-2009, 08:12 PM

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