Solved Field visible & invisible in form (1 Viewer)

iaasiqbal

New member
Local time
Today, 19:47
Joined
Mar 30, 2022
Messages
26
Please help to write the condition

IET = Income Expenditure Type
IET = "", "Income", "Expense"

in my data entry form -when IET is blank or null the two field debit & credit will be in visible, and IET = Income the credit field will be visible and debit field is invisible
and IET = Expense the debitfield will be visible and credit field is invisible



Private Sub Form_Current()

If IET = "" Then
DEBIT.Visible = False
CREDIT.Visible = False

If IET = "Income" Then
CREDIT.Visible = True
DEBIT.Visible = False

If IET = "Expense" Then
DEBIT.Visible = True
CREDIT.Visible = False

End If

End Sub
 

isladogs

MVP / VIP
Local time
Today, 13:47
Joined
Jan 14, 2017
Messages
18,186
Here's one solution

Code:
Private Sub Form_Current()

Select Case IET

Case "Income"
   CREDIT.Visible = True
   DEBIT.Visible = False

Case Expense
   DEBIT.Visible = True
   CREDIT.Visible = False

Case Else
   DEBIT.Visible = False
   CREDIT.Visible = False

End Select

End Sub
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:47
Joined
Feb 19, 2013
Messages
16,555
Your code should work but a bit long winded. All you need is

Code:
Private Sub Form_Current()

    DEBIT.Visible = IET = "Expense"
    CREDIT.Visible = IET = "Income"

End If

This assumes the default value for the IET control is ""

Note the visible property is only relevant for a single form, if continuous, then this and your code (and Colin's) will affect all rows
 

iaasiqbal

New member
Local time
Today, 19:47
Joined
Mar 30, 2022
Messages
26
DEBIT.Visible = IET = "Expense" CREDIT.Visible = IET = "Income"
thanks , this will work with existing data but
it will show error to add new data


1660559954374.png
 

isladogs

MVP / VIP
Local time
Today, 13:47
Joined
Jan 14, 2017
Messages
18,186
Did you also try my version?
If that errors replace
Select Case IET
with
Select Case Nz(IET,"")
 

iaasiqbal

New member
Local time
Today, 19:47
Joined
Mar 30, 2022
Messages
26
Did you also try my version?
If that errors replace
Select Case IET
with
Select Case Nz(IET,"")

thanks this is working but debit /credit field not display for new data entry. please help, i upload my database
 

Attachments

  • VGLsV1.zip
    444.4 KB · Views: 97

CJ_London

Super Moderator
Staff member
Local time
Today, 13:47
Joined
Feb 19, 2013
Messages
16,555
Have you set the default value per post #7

I don't see an uploaded database?
 

isladogs

MVP / VIP
Local time
Today, 13:47
Joined
Jan 14, 2017
Messages
18,186
You don't need Case "" as its covered by Case Else
In line with your instructions, the fields aren't visible in a new record as IET is initially null
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:47
Joined
Feb 19, 2013
Messages
16,555
if you don't want to apply a default value use

Code:
Private Sub Form_Current()

    DEBIT.Visible = nz(IET,"") = "Expense"
    CREDIT.Visible = nz(IET,"") = "Income"

End If
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 13:47
Joined
Sep 12, 2006
Messages
15,614
Seriously, you could avoid all of this by just having a single column or field/testbox, and including a minus sign for credit values.

Using computers for accounting entries means you should probably deal with debits and credits in a different way, and it's far easier.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:47
Joined
Feb 19, 2013
Messages
16,555
I've written a number of accounting systems over the years and I store all values as positive because that is easier for the user. I use the transaction type chosen (Dr or Cr) to convert to a negative is necessary when calculating balances. Depends on which way you want to go with it but I include a multiplier which can either be a calculation or in a simple lookup table e.g.

tblTranTypes
TranType....Multiplier
Income.......1
expense.....-1

then the balance calculation in a query would be

Balance: Sum(Amount*multiplier)

Doesn't change the basic requirement of this thread except instead of messing around with control visibility, you just use your iet combo as the label for the control amount.
 

Users who are viewing this thread

Top Bottom