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:
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.
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