If Then Else error

P

Peter Stone

When I click a Command button I want to open one of two forms depending on a
value in the field: Progress in the table: tblText.

I get the Error Message: Object required

The answer is probably simple, but I'm a novice in a remote location and
until a friend brings me a manual in a few weeks I have no other resources.

Private Sub cmdPublishUpdate_Click()
On Error GoTo Err_cmdPublishUpdate_Click
Dim stDocName As String
Dim stLinkCriteria As String
If Tables!tblText!Progress < 9 Then
stDocName = "frmNotEdited"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
stDocName = "frmPublish1"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmdPublishUpdate_Click:
Exit Sub
End If

Err_cmdPublishUpdate_Click:
MsgBox Err.Description
Resume Exit_cmdPublishUpdate_Click

End Sub


Thanks

Peter
 
G

Graham Mandeno

Hi Peter

The bit that makes no sense is Tables!tblText!Progress.

Is "Progress" a field on the form containing your command button?

If so, then you can just refer to it without qualification:

If Progress < 9 Then

Also, your End If is misplaced. It should be *before*
Exit_cmdPublishUpdate_Click.

Finally, you can tidy the code somewhat by not repeating the OpenForm line,
but instead put it outside the If block:

If Progress < 9 Then
stDocName = "frmNotEdited"
Else
stDocName = "frmPublish1"
End If
DoCmd.OpenForm stDocName, , , stLinkCriteria
 
P

Peter Stone

Thanks Graham

I cleaned up the subroutine in the manner you suggested (much neater). My
problem was related to the fact that the required value was selected by an
option button in a frame (bofProgress) and I didn't know how to refer to a
frame/option button.

Your help focused me on the problem and after several attempts, I replaced

If Tables!tblText!Progress < 9 Then

with

If bofProgress <> 9 Then

which worked fine (next time I'll try the simplest options first)

Thanks again

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top