Code:
1 Private Sub Command51_Click()
2 Dim mainForm As String
3 Dim strMsg As String
4 Dim strForm As String
5 Dim strInput As String
6 Dim myVar As String '<<<-- initialized
7 strForm = "frmCNAFCHGReqSubmitForm"
8 mainForm = "frmCNAFCHGReqMenu"
9 myVar = "[ID]=" & strInput ' <<--- "myVar" value is now "[ID]=" because, at this point, "strInput" is equal to "" (empty string)
10 Beep
11 strMsg = "This form is to be edited by the original requester of the change request only!" & vbCrLf & vbLf & "Please enter ID number of original change request at this time."
12 strInput = InputBox(strMsg, "Change Request ID Number") '<<<--- "strInput" should have a value
13 If strInput = myVar Then ' <<<---comparing an entry to an empty string
14 DoCmd.Close acForm, "frmCNAFCHGReqMenu", acSaveNo
15 DoCmd.OpenForm strForm, acNormal, , myVar
16 Else 'password is incorrect
17 MsgBox "Incorrect CNAF Change Form ID Number!" & vbCrLf & vbLf & "You are not allowed access unless the correct Change Form ID number is used.", vbCritical, "Please Try Again"
18 End If
19 End Sub
It looks to me that strInput will never equal myVar.
You said
If the ID does not exist in the field as a value,
If I may make a suggestion... maybe try this modified code:
Code:
Private Sub Command51_Click()
Dim mainForm As String
Dim strMsg As String
Dim strForm As String
Dim strInput As String
Dim myVar As String
strForm = "frmCNAFCHGReqSubmitForm"
mainForm = "frmCNAFCHGReqMenu"
'get the value from the current form record source
myVar = Me.Your_ID_Field_Name '<<<--- change to your field name
'maybe:
' myVar = Me.ID
Beep
strMsg = "This form is to be edited by the original requester of the change request only!"
strMsg = strMsg & vbCrLf & vbLf
strMsg = strMsg & "Please enter ID number of original change request at this time."
strInput = InputBox(strMsg, "Change Request ID Number")
If strInput = myVar Then
DoCmd.Close acForm, mainForm
DoCmd.OpenForm strForm, acNormal, , "[ID]=" & myVar
Else 'password is incorrect
MsgBox "Incorrect CNAF Change Form ID Number!" & vbCrLf & vbLf & "You are not allowed access unless the correct Change Form ID number is used.", vbCritical, "Please Try Again"
End If
End Sub
(My changes are in BLUE)
BTW, this line
Code:
DoCmd.Close acForm, "frmCNAFCHGReqMenu", acSaveNo
doesn't do what you think it does.
The argument "acSaveNo" is for changes to the DESIGN of the form using VBA, not changes to the data.
Since you didn't makes changes to the design of the form, this argument doesn't have any effect.