A family of Microsoft relational database management systems designed for ease of use.
Is it a text box, or a combo box as you first said? That really doesn't matter to the error, but it's good to be precise about these things.
The first thing to realize is that, if you enter something in the text box (or combo box) and then delete that entry, the control's AfterUpdate event is still going to fire, even if you completely deleted the contents of the control. As far as Access is concerned, you modified that control to set its value to Null. So your AfterUpdate code has to allow for the possibility that the control is Null. For a text box, if the control is bound to a text field, or is unbound, you may also have to allow for the possibility that its value is a zero-length string; that is, "".
Therefore, your code probably wants to check for Null and zero-length string before taking any other action. You could do that like this:
If IsNull(Me.txtProg) Or Me.txtProg = vbNullString Then Exit Sub
I generally do it like this, though:
If Len(Me.txtProg & vbNullString) = 0 Then Exit Sub
The above statement concatenates the control's value with a zero-length string, and then tests the length of that string. Regardless of whether txtProg is Null or a zero-length string, the result of the concatenation is a zero-length string.
You code also has an error later on. You say:
If txtProg = 1 And 2 Then '*** ERROR
That code will apply the bitwise AND operation to the values of 1 and 2, repectively, which will yield the value of 0. Bit-wise, the integer value of 1 is 0000000000000001, and the value of 2 is 0000000000000010. If you "AND" those bits together, you get:
0000000000000001
AND 0000000000000010
----------------------
0000000000000000
So the statement "If txtProg = 1 And 2 Then" is equivalent to "If txtProg = 0 Then", which is almost certainly not what you intended.
What you probably intended is:
If Me.txtProg = 1 Or Me.txtProg = 2 Then
So that the value of txtProg is 1 or 2, then the DoCmd.OpenForm statement will be executed.
I note, though, that in your Select Case statement, you assign a zero-length string to strDoc when txtProg = 2. But your later If statement, if I interpret your intention correctly, will try to open a form whose name is held in strDoc if txtProg = 2 -- but in that case the code would have set strDoc to "". So maybe I'm not interpreting your intentions correctly.