Results 1 to 1 of 1
  1. #1
    ThunderSpark is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    32

    Programming A Loan Article Update Querry in VBA.

    Note: This Article is related to one of my previous posts which you can find here: https://www.accessforums.net/showthread.php?t=77356


    I am currently in the next step of my assignment trying to program a Loan Article system in a doc manager database where the availability of the Article, and even the date and name of the Loaner is kept in a Querry. So far the "Skeleton Forms" are finished, so all the buttons and Fields are there. Even when certain fields get "blocked" and reset to a default Value under certain circumstances. To illustrate this is what going to happen:
    Click image for larger version. 

Name:	Naamloos.jpg 
Views:	9 
Size:	95.4 KB 
ID:	38883


    Currently this is the code that is already active.

    Main Form
    The one the left in the screenshot:
    Code:
    Private Sub Form_Load()
        If LenB(glngId) = 0 Then
            Me.Recordset.FindFirst "[aanwinstnr] = '1'"
        Else
            Me.Recordset.FindFirst "[aanwinstnr] = '" & glngId & "'"
        End If
        If txtstatus.Value = "Beschikbaar" Then
        txtuitlener.Enabled = False
        txtuitlener.DefaultValue = vbNullString
        txtuitgeleendtot.Enabled = False
        txtuitgeleendtot.DefaultValue = vbNullString
        Else
        txtuitlener.Enabled = True
        txtuitgeleendtot.Enabled = True
     End If
    End Sub
    In short this code allows me to disable and make the fields vbNullString when the Status = "beschikbaar" (availabel)

    The Subform that opens with the button on the Main Form.

    Code:
    Private Sub Form_Load()
    If lstTUI__lstTUI.Value = "Intern" Then
     lstNUIT.Visible = True
     txtNUIT.Visible = False
     txtNUIT.DefaultValue = vbNullString
     Else
     lstNUIT.Visible = False
     txtNUIT.Visible = True
     lstNUIT.DefaultValue = vbNullString
     End If
    If txtstatus.Value = "Uitgeleend" Then
        lstTUI__lstTUI.Enabled = False
        lstNUIT.Enabled = False
        txtNUIT.Enabled = False
        Datum.Enabled = False
        Knop76.Enabled = False
        Knop83.Enabled = True
    Else
        txtNUIT.Enabled = True
        Datum.Enabled = True
        Knop76.Enabled = True
        Knop83.Enabled = False
        txtuitlener.Enabled = False
        txtuitlener.DefaultValue = vbNullString
        txtuitgeleendtot.Enabled = False
        txtuitgeleendtot.DefaultValue = vbNullString
    End If
    End Sub
    Note as I said this is related to the this topic https://www.accessforums.net/showthread.php?t=77356 about two specific fields in the forms.
    Note: Knop (Button) 76 is the Button that one can press to "Loan the Article". Knop (button) 83 however is the button that is blocked when the Article is not Loaned but becomes availabel when the Article is Loaned.
    Illustration.

    Click image for larger version. 

Name:	Uitleen Formulier.png 
Views:	9 
Size:	31.2 KB 
ID:	38885

    It is these two buttons that should be tied down to the update Querry. So how do I do this? Also note: right now there does not currently exist a querry to keep the Loan data.

    Edit: So far the Form has been program right however there is a problem with the Details. I will post these later in a future edit.

    My Appologies for posting this question it seems I have solved my own Problem. I will be sharing the code here:

    Code:
    Private Sub Form_AfterUpdate()
    If txtstatus.Value = "Beschikbaar" Then
        Knop76.Enabled = True
        Knop83.Enabled = False
        ElseIf txtstatus.Value = "Uitgeleend" Then
        Knop76.Enabled = False
        Knop83.Enabled = True
        End If
    End Sub
    Private Sub Form_Load()
        If LenB(glngId) = 0 Then
            Me.Recordset.FindFirst "[aanwinstnr] = '1'"
        Else
            Me.Recordset.FindFirst "[aanwinstnr] = '" & glngId & "'"
        End If
    
    If lstTUI__lstTUI.Value = "Intern" Then
     lstNUIT.Visible = True
     txtNUIT.Visible = False
     txtNUIT.DefaultValue = vbNullString
     Else
        If lstTUI__lstTUI.Value = "Entern" Then
     lstNUIT.Visible = False
     txtNUIT.Visible = True
     lstNUIT.DefaultValue = vbNullString
     End If
    If txtstatus.Value = "Uitgeleend" Then
        lstTUI__lstTUI.Enabled = False
        lstNUIT.Enabled = False
        txtNUIT.Enabled = False
        Datum.Enabled = False
        Knop76.Enabled = False
        Knop83.Enabled = True
    ElseIf txtstatus.Value = "Beschikbaar" Then
        txtNUIT.Enabled = True
        Datum.Enabled = True
        Knop76.Enabled = True
        Knop83.Enabled = False
        txtuitlener.Enabled = False
        txtuitlener.DefaultValue = vbNullString
        txtuitgeleendtot.Enabled = False
        txtuitgeleendtot.DefaultValue = vbNullString
        End If
    End If
    End Sub
    Private Sub Knop76_Click()
    On Error GoTo Err_Knop76_Click
    STATUS.Value = "Uitgeleend"
    UITGELEENDOP.Value = Datum
          If lstTUI__lstTUI.Value = "Intern" Then
          UITLENER.Value = lstNUIT.Value
          ElseIf lstTUI__lstTUI.Value = "Extern" Then
          UITLENER.Value = txtNUIT
          End If
    Me.Refresh
    Exit_Knop76_Click:
        Exit Sub
    Err_Knop76_Click:
        MsgBox Err.Description
        Resume Exit_Knop76_Click
    End Sub
    Private Sub Knop83_Click()
    On Error GoTo Err_Knop83_Click
    STATUS.Value = "Beschikbaar"
    txtNUIT.Enabled = True
    lstTUI__lstTUI.Enabled = True
    
    txtuitlener.Value = vbNullString
    UITLENER.Value = vbNullString
    UITGELEENDOP.Value = vbNullString
    Me.Refresh
    Exit_Knop83_Click:
        Exit Sub
    Err_Knop83_Click:
        MsgBox Err.Description
        Resume Exit_Knop83_Click
    Exit_FORM
    
    End Sub
    
    Private Sub lstTUI__lstTUI_AfterUpdate()
    If lstTUI__lstTUI.Value = "Intern" Then
     lstNUIT.Visible = True
     txtNUIT.Visible = False
     txtNUIT.DefaultValue = vbNullString
     Else
     lstNUIT.Visible = False
     txtNUIT.Visible = True
     lstNUIT.DefaultValue = vbNullString
     End If
    End Sub




    Last edited by ThunderSpark; 06-25-2019 at 08:19 AM.

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

Similar Threads

  1. Cant execute a update querry
    By Fairportjay in forum Programming
    Replies: 3
    Last Post: 05-06-2019, 10:27 AM
  2. Update Querry
    By Daryl2106 in forum Access
    Replies: 6
    Last Post: 08-29-2013, 11:09 AM
  3. update querry Problem
    By newtoAccess in forum Queries
    Replies: 1
    Last Post: 04-04-2011, 09:33 AM
  4. Update Querry
    By wrenchman123 in forum Queries
    Replies: 0
    Last Post: 02-05-2011, 07:21 AM
  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