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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

One Button opens one of three forms

Status
Not open for further replies.

andrimitum

Programmer
May 24, 2007
8
CA
Hi all,

I am sure this is simple but it has wasted most of my day.

I have one button on my main form that depending on the results in two seperate fields on my main form will open one of three optional forms when clicked.

My three forms I want to optionally call and the criteria are:
CheckListEO when field ApprovalType = "eo"
CheckListLSTC when field ApprovalType<> "eo" and field Customer = "Prangers"
CheckListOther When ApprovalType<> "eo" and Customer <> "Prangers"

This is not my code, I am lost writing it and have tried everything I can think of so here is what I am trying to achive.

eg.
If ApprovalType = "eo" then [Forms]![CheckListEO] else, (If Customer = "Prangers" then [Forms]![CheckListLSTC] else [Forms]![CheckListOther])

Any help would be appreciated and BTW I am not a programer, I have no idea how I got that designation attached to my profile and can't seem to change it.

Andri
 
if ApprovalType = "eo" then
docmd.openform "CheckListEO"
else
if Customer = "Prangers" then
docmd.openform "CheckListLSTC"
else
docmd.openform "CheckListOther"
end if


endnif
 
Thanks but I am getting the same error I have been getting most of the day "Object doesn't support this property of method"

Any Ideas?

Code:

Private Sub Command161_Click()
On Error GoTo Err_Command161_Click


If ApprovalType = "eo" Then
DoCmd.OpenForm "CheckListEO"
Else
If Customer = "Prangers" Then
DoCmd.OpenForm "CheckListLSTC"
Else
DoCmd.OpenForm "CheckListOther"
End If
End If

Err_Command161_Click:
MsgBox Err.Description
Resume Exit_Command161_Click

Exit_Command161_Click:
Exit Sub

End Sub
 
Try:

Code:
Private Sub Command161_Click()
On Error GoTo Err_Command161_Click
 

If Me.ApprovalType = "eo" Then
  DoCmd.OpenForm "CheckListEO"
Else
  If Me.Customer = "Prangers" Then
    DoCmd.OpenForm "CheckListLSTC"
  Else
    DoCmd.OpenForm "CheckListOther"
  End If
End If

Exit_Command161_Click:
    Exit Sub

Err_Command161_Click:
    MsgBox Err.Description
    Resume Exit_Command161_Click

 
End Sub

If this does not work, please report the line where the error occurs.

It is generally best to use proper names (eg cmdOpenForm) for command buttons, you will thank yourself later. It is also a good idea to prefix controls to prevent them from being confused with fields (eg txtApproval). You may wish to look at naming conventions.

 
It is working now Remou, thank you.

Sometimes you just need to sleep on something and get the help of someone who knows something to fix the problem.

I did as you suggested above but still got the same error message. I double checked the ApprovalType field name and realized I had renamed it ApprovalType1 some time in the past when I had created a combo box to replace the original field. ApprovalType was the underlying field in the table but did not exist as a field on my form......

So..... after inserting the code you suggested above and then making the name change everything works perfectly.

Thanks a lot Remou and Pwise.

As for naming conventions. I do not typically accept the default name but in this case due to frustration I took it planning to change it if I ever got it to work. I have and I have :)

I have only started paying attention to naming conventions recently though so I have a lot of clean up to do on this DataBase.

Thanks again,
Andri
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top