QUOTE(Kinnison @ 27 Jun, 2009 - 04:09 PM)

In my source code, it has this same long code assigned to 60 buttons:
CODE
intRoomNumber = 1
frmInformation.Hide
frmConfirm.Hide
lblGuestName.Caption = strName(intRoomNumber)
lblCheckIn.Caption = dtmCheckIn(intRoomNumber)
lblCheckOut.Caption = dtmCheckOut(intRoomNumber)
lblID.Visible = True
lblInfo(0).Visible = True
lblGuestName.Visible = True
lblID.Caption = intRoomNumber
If blnTaken(intRoomNumber) = True Then
lblInfo(0).Visible = True
lblInfo(1).Visible = True
lblInfo(2).Visible = True
lblInfo(3).Visible = True
lblTaken.Visible = True
lblCheckIn.Visible = True
lblCheckOut.Visible = True
cmdOK.Enabled = True
cmdDetails.Enabled = True
cmdCheckIn.Enabled = False
cmdCheckOut.Enabled = True
cmdReserve.Enabled = False
cmdRevert.Enabled = False
ElseIf blnReserve(intRoomNumber) = True Then
cmdOK.Enabled = True
cmdDetails.Enabled = False
cmdCheckIn.Enabled = False
cmdCheckOut.Enabled = False
cmdReserve.Enabled = False
cmdRevert.Enabled = True
lblReserved.Visible = True
Else
lblVacant.Visible = True
cmdOK.Enabled = True
cmdDetails.Enabled = False
cmdCheckIn.Enabled = True
cmdCheckOut.Enabled = False
cmdReserve.Enabled = True
cmdRevert.Enabled = False
End If
It was troubling to have it pasted 60 times in the same button plus its gonna cost me more for printing so I need to shorten this up. Not removing unnecessary strings in the code but its usage, meaning that I don't have to paste the same code for 60 times.
Is there a way I can use to simplify the code and solve my problem?
I was thinking if I can put this one in a Module and then call the entire code out in any form whenever I wanted.
Hi K...
I think that if you put it in a module it will only result in an error why not use a function with parameters
exmaple of the function:
Function name is Toggle..
CODE
Function Toggle(btnOK As Boolean, btndetails As Boolean, btnCheckin As Boolean, btnCheckout As Boolean, btnReserve As Boolean, btnRevert As Boolean)
cmdOK.Enabled = btnOK
cmdDetails.Enabled = btndetails
cmdCheckIn.Enabled = btnCheckin
cmdCheckOut.Enabled = btnCheckout
cmdReserve.Enabled = btnReserve
cmdRevert.Enabled = btnRevert
End Function
So if you use the function to your code it will look like this:
CODE
frmInformation.Hide
frmConfirm.Hide
lblGuestName.Caption = strName(intRoomNumber)
lblCheckIn.Caption = dtmCheckIn(intRoomNumber)
lblCheckOut.Caption = dtmCheckOut(intRoomNumber)
lblID.Visible = True
lblInfo(0).Visible = True
lblGuestName.Visible = True
lblID.Caption = intRoomNumber
If blnTaken(intRoomNumber) = True Then
lblInfo(0).Visible = True
lblInfo(1).Visible = True
lblInfo(2).Visible = True
lblInfo(3).Visible = True
lblTaken.Visible = True
lblCheckIn.Visible = True
lblCheckOut.Visible = True
Toggle True,True,False,True,False,False
ElseIf blnReserve(intRoomNumber) = True Then
lblReserved.Visible = True
Toggle True,False,False,False,False,True
Else
lblVacant.Visible = True
Toggle True,False,True,False,True,False
End If
and don't forget to include the function in to your form
hope this will help you...