Combo Boxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djenkins728
    New Member
    • Jul 2007
    • 10

    #16
    Originally posted by JKing
    What are the data types of the fields Dept and [Called By]? Are they numbers or are they text?

    They are both text fields.

    Comment

    • JKing
      Recognized Expert Top Contributor
      • Jun 2007
      • 1206

      #17
      When using SQL strings with VBA variables of the text type need to be enclosed with single quotes.

      [code=vb]Private Sub cmd_Submit_Clic k()
      On Error GoTo Err_cmd_Submit_ Click

      Dim stDocName As String
      Dim stLinkCriteria As String

      stDocName = "frm_maininfofi lter"
      stLinkCriteria = ""
      If Not IsNull(Me.cbo_d eptselect) Then
      stLinkCriteria = "Dept = '" & Me.cbo_deptsele ct & "'"
      End If
      If Not IsNull(Me.cbo_C alledby) Then
      If stLinkCriteria = "" Then
      stLinkCriteria = "[Called By] = '" & Me.cbo_Calledby & "'"
      Else
      stLinkCriteria = stLinkCriteria & " And [Called By] = '" & Me.cbo_Calledby & "'"
      End If
      End If
      DoCmd.OpenForm stDocName, , , stLinkCriteria

      Exit_cmd_Submit _Click:
      Exit Sub

      Err_cmd_Submit_ Click:
      MsgBox Err.Description
      Resume Exit_cmd_Submit _Click
      End Sub[/CODE]

      Give that a go.

      Comment

      • djenkins728
        New Member
        • Jul 2007
        • 10

        #18
        Originally posted by JKing
        When using SQL strings with VBA variables of the text type need to be enclosed with single quotes.

        [code=vb]Private Sub cmd_Submit_Clic k()
        On Error GoTo Err_cmd_Submit_ Click

        Dim stDocName As String
        Dim stLinkCriteria As String

        stDocName = "frm_maininfofi lter"
        stLinkCriteria = ""
        If Not IsNull(Me.cbo_d eptselect) Then
        stLinkCriteria = "Dept = '" & Me.cbo_deptsele ct & "'"
        End If
        If Not IsNull(Me.cbo_C alledby) Then
        If stLinkCriteria = "" Then
        stLinkCriteria = "[Called By] = '" & Me.cbo_Calledby & "'"
        Else
        stLinkCriteria = stLinkCriteria & " And [Called By] = '" & Me.cbo_Calledby & "'"
        End If
        End If
        DoCmd.OpenForm stDocName, , , stLinkCriteria

        Exit_cmd_Submit _Click:
        Exit Sub

        Err_cmd_Submit_ Click:
        MsgBox Err.Description
        Resume Exit_cmd_Submit _Click
        End Sub[/CODE]

        Give that a go.

        Thanks JKing. I don't receive the parameter value box anymore, but when the form opens it's blank. Within this code where would I add the other two combo boxes, cbo_boat and cbo_type?

        Comment

        • djenkins728
          New Member
          • Jul 2007
          • 10

          #19
          I'm still trying to add the two other combo boxes for the selection criteria and then open a form. The other two are cbo_boat and cbo_type. Since cbo_dept updates after the selection of cbo_calledby I added code to attempt to update cbo_boat, but nothing happens. Can someone help?

          Code:
          Private Sub cbo_Calledby_AfterUpdate()
              With Me![cbo_deptselect]
                  If IsNull(Me!cbo_Calledby) Then
                      .RowSource = " "
                  Else
                      .RowSource = "Select DISTINCT [dept] " & _
                                   "From tbl_trial " & _
                                   "Where [calledby_id]=" & Me!cbo_Calledby
                  End If
                          
              Call .Requery
              End With
           End Sub
          Private Sub cbo_deptselect_AfterUpdate()
             With Me![cbo_boat]
                  If IsNull(Me!cbo_deptselect) Then
                      .RowSource = " "
                  Else
                      .RowSource = "Select DISTINCT [boat] " & _
                                   "From tbl_trial " & _
                                   "Where [calledby_id]= '" & Me!cbo_Calledby & "'"
                  End If
              Call .Requery
              End With
          End Sub
          Last edited by NeoPa; Aug 1 '07, 05:35 PM. Reason: [CODE] tags again. Warning to follow.

          Comment

          Working...