View Single Post
  #2 (permalink)  
Old October 7th, 2003, 11:02 AM
Bob Bedell Bob Bedell is offline
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

This might help you a little furter along. First, altering your click event's parameter list signature as you are won't help. The click event can't recieve arguments that way. Second, your function needs to return a value and doesn't. The following code assumes you have 1 checkbox associated with one text box (though I'm not clear that that is what you mean):

I created 1 standard module to handle your data access and select the appropriate value based on the check box selected:

Public Function StandardValues(strField As String) As String

    Dim rst As ADODB.Recordset
    Dim cnn As ADODB.Connection
    Dim intTextBoxValue As Integer

    Set rst = New ADODB.Recordset
    Set cnn = CurrentProject.Connection
    rst.Open "SELECT tblStandard.* FROM tblStandard", cnn, adOpenKeyset, , adCmdText

    Select Case strField
        Case "Name"
            StandardValues = rst(0)
        Case "Address"
            StandardValues = rst(1)
        Case "Phone"
            StandardValues = rst(2)
        Case "TaxRate"
            StandardValues = rst(3)
    End Select

    rst.Close

End Function

The function recieves a field name as an argument and returns a string value to the calling procedure by assigning the recordset field value to the function name.

The code for the check box click events looks like this(I did Name and TaxRate):

Private Sub chkNameTextBox_Click()
    Dim strValue As String
    Dim strFieldName As String

    strFieldName = "Name"

    strValue = StandardValues(strFieldName)
    txtName = strValue
End Sub

Private Sub chkTaxCheckBox_Click()
    Dim strValue As String
    Dim strFieldName As String

    strFieldName = "TaxRate"

    strValue = StandardValues(strFieldName)
    txtTax = strValue

End Sub

The event handlers pass a field name to the fucntion and recieve a value back.

HTH,

Bob


Reply With Quote