Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ISSUE WITH IF-THEN-ELSE STATEMENT 1

Status
Not open for further replies.

penndro

Technical User
Jan 9, 2005
108
US
On my form I have a button [LOCKRECORD] that is being used to lock a persons file.

When the button if pressed TWO things must occur –

(1) the program checks to see if the record is already locked – if it is then the user is given a message that the record is already locked.
(2) If the record is not locked then – then the system must verify with the user that they want to indeed lock the record using an input from the message box.

I was able to get the form to lock initially however – because I am looking for two things – if the record is unlocked it will show the message box BUT if I select CANCEL – it still locks the record.

Here is the code:

Private Sub btnLockFile_Click()
If cboRecordLock = True Then
MsgBox "This Record is Already Locked " & vbCrLf & _
"and Can Not Be Unlocked or Altered", vbExclamation
Else
Dim cboInput As Boolean
Dim booLocked As Boolean

intResponse = MsgBox("You are About to Permanently Lock " & _
"This Record. If You Proceed," & vbCrLf & _
"This Record Will Be Disabled and Can Not Be " & vbCrLf & _
"Edited or Altered. To Continue Press YES" & vbCrLf & _
"or Press NO or CANCEL to Dismiss This Action", _
vbOKCancel + vbQuestion + vbDefaultButton1, _
"Critical Information")
cboInput = intResponse

If cboInput = 1 Then
cboRecordLock = cboInput
txtDateLocked = Date
txtLockBy = CurrentUser()
imgLock.Visible = True
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
booLocked = True
cboRecordLock.Locked = booLocked
txtDateLocked.Locked = booLocked
txtLockBy.Locked = booLocked
Me.txtFirst.Locked = booLocked
Me.txtLast.Locked = booLocked
Me.txtMaiden.Locked = booLocked
Me.txtPrefix.Locked = booLocked
Me.txtAddress.Locked = booLocked
Me.txtCity.Locked = booLocked
Me.txtState.Locked = booLocked
Me.txtZip.Locked = booLocked
Me.txtCountry.Locked = booLocked
Me.txtHomePhone.Locked = booLocked
Me.txtWorkPhone.Locked = booLocked
Me.txtEmail.Locked = booLocked
Me.subformCampExperiences.Locked = booLocked
Me.subformDPCampExperience.Locked = booLocked
Me.subformSovietExperience.Locked = booLocked
Me.subformRescuerExperience.Locked = booLocked
Me.SubFormLiberators.Locked = booLocked
Me.subformPOW.Locked = booLocked
Me.SubfrmResistance.Locked = booLocked
Me.subformHiding.Locked = booLocked
Me.SubFormPartisanExperience.Locked = booLocked
Me.SubFormDeathMarch.Locked = booLocked
Me.SubFormInterviewStatus.Locked = booLocked
Me.subformGhettoExperiences.Locked = booLocked
Me.subFormMigrationExperiences.Locked = booLocked
cboRecordLock.Locked = booLocked
txtDateLocked.Locked = booLocked
txtLockBy.Locked = booLocked
End If

End Sub
 
First, you're missing an "End If" at the end of the procedure.

Second, the problem is this line:

Code:
cboInput = intResponse

intResponse = 1 (vbOK) or 2 (vbCancel), which are both interpreted as True. So, replace this code:

Code:
cboInput = intResponse
        
If cboInput = 1 Then

With this:

Code:
If intResponse = vbOK Then

and remove the Dim statement for cboInput.
 
Geoff,

Good point. penndro, the second if statement should go within the else, and then there should be two "End If"s at the end.
 
Thanks - worked beautifully.

How about some help with my other thread - AUTOFILL A FIELD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top