Configuring Check Out Button To Update Field Value of another table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hicksmk2
    New Member
    • Jul 2021
    • 1

    Configuring Check Out Button To Update Field Value of another table

    I will try to explain this to the best I can.

    Currently, I am creating an asset inventory system. In the system, I have 2 tables (IT Assets and Contacts) and 3 separate forms (AssetEntry-F, AssetChecking-F, and Employee-F). I am in the process of creating the AssetChecking-F form, that will serve the purpose of checking in and checking out the asset once it is scanned via barcode. On the form, I have a text box, in which the user will scan the barcode on the item, and then either click the button for check in (which will populate a date and change the status of "In Stock" field on the IT Assets Table to true) or click the check out button (which will prompt the user for the first and last name of the user via InputBox, set the timestamp of check out, and change the "In Stock" field status to False.

    The problem that I'm having (with the Check-Out button) is how to set the variables that I have created for grabbing the First & Last Name to update the fields (First Name, Last Name) on the Contacts Table since the AssetChecking-F form has the record source set for "IT Assets". Here is an example of my VBA code in progress (I am open to all feedback)
    Code:
    Private Sub AssetOut_Click()
    
    Dim getOwnerFirst As String
    Dim getOwnerLast As String
    
    getOwnerFirst = InputBox("Please associate the device with an owner. Enter the owner's first name", [Get Owner - First Name])
    getOwnerLast = InputBox("Please enter the owner's last name", [Get Owner Last Name])
    
    If getOwnerFirst = “” Or IsNull(getOwnerFirst) Then
    
               ‘do Nothing
    
           Else
           
    If getOwnerLast = “” Or IsNull(getOwnerLast) Then
    
               ‘do Nothing
    
           Else
           
    Me.TimeOut = Date
    
    Me.[In Stock] = False
    
    End Sub
    Last edited by NeoPa; Jul 1 '21, 10:32 PM. Reason: Added [CODE] tags.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32661

    #2
    One easy fix is never to use a word processor to work with code. They typically update actual quote characters (' & ") to the ones used in letters or emails and shown in your code (“, ” & ‘) which just don't work as expected or required.

    That's one of the reasons why we insist on posts including the [CODE] tags when code is used. That font shows up such errors quickly & obviously whereas the standard text font obscures the differences.

    Originally posted by HicksMk2
    HicksMk2:
    The problem that I'm having (with the Check-Out button) is how to set the variables that I have created for grabbing the First & Last Name to update the fields (First Name, Last Name) on the Contacts Table since the AssetChecking-F form has the record source set for "IT Assets".
    The problem I'm having is that you haven't introduced or explained what these variables are nor what you're trying to do with them before referring to them in your explanation. I love that you're explaining the best that you can, but unfortunately I still need it to make sense if I'm to understand what you're doing & what might be going wrong.

    Typically, and I'm guessing here by reading between the lines a bit, if you want to associate two records with each other, and like all good & helpful developers you want to do it in a way that makes it as easy as possible, and as reliable as possible, for your users, then you use a reference ID in one table that matches a reference ID in another.

    Now, we know that users (Human thingies.) tend to struggle with reference IDs because their brains are taught to deal with names rather than such things. So, what we typically do is present to them a list of items that show names (In a ComboBox or ListBox Control on the Form.) but also have reference ID data associated with each row so that the code can reference the reference ID once the user has selected the name.

    This approach is less open to users being unable to spell very well, or even type without hitting the wrong keys. In real life this is very important as they tend to do this quite a lot.

    Comment

    Working...