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

Case Statement based on combo box input 1

Status
Not open for further replies.

SOMSteve

Technical User
Joined
May 17, 2007
Messages
27
Location
US
I am attempting to use a "Select Case" statement that references a combo box on a form (not linked to a table) to open up the appropriate form for the database user. When I execute the code, I get an error: "Object required." I've seen this problem appear elsewhere in the messageboards, but was unable to determine what I am doing wrong based on other member's postings. Since I am new to coding figuring this out has been difficult. I am unsure as to whether the order of my coding is correct, if I need other dim and set statements after the Select Case coding, and if the combo box is being referenced correctly. Below is my code. Any guidance would be greatly appreciated, thanks!

-Steve


Code
Private Sub cboSelectTransferType_AfterUpdate()
On Error GoTo Err_cboSelectTransferType_AfterUpdate

DoCmd.Close

Dim stDocName As String
Dim stLinkCriteria As String

'Trying to reference form "frmTransferSelect" and the combo box "cboSelectTransferType"
Select Case (frmTransferSelect.cboSelectTransferType)
Case "Live Auction"
stDocName = "frmLiveAuction"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
Case "Local Bid"
stDocName = "frmLocalBid"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
Case "MiBid"
stDocName = "frmMiBid"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
Case "Sealed Bid"
stDocName = "frmSealedBid"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
Case "State Agency"
stDocName = "frmToStateAgency"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
Case Else
stDocName = "frmTransfers"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
End Select

Exit_cboSelectTransferType_AfterUpdate:
Exit Sub

Err_cboSelectTransferType_AfterUpdate:
MsgBox Err.Description
Resume Exit_cboSelectTransferType_AfterUpdate

End Sub

 
I think the che culprit is DoCmd.Close
You'll reference a combo on a form you just closed.
What about this ?
Code:
Private Sub cboSelectTransferType_AfterUpdate()
Dim stDocName As String
Dim stLinkCriteria As String
Select Case Me!cboSelectTransferType
Case "Live Auction"
    stDocName = "frmLiveAuction"
Case "Local Bid"
    stDocName = "frmLocalBid"
Case "MiBid"
    stDocName = "frmMiBid"
Case "Sealed Bid"
    stDocName = "frmSealedBid"
Case "State Agency"
    stDocName = "frmToStateAgency"
Case Else
    stDocName = "frmTransfers"
End Select
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks! I had snuck that close command in there, but obviously in the wrong spot. Your correction did the trick, I really appreciate the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top