Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 7th, 2003, 07:24 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default using fields in recordset to populate textbox


I have a db on a company in which I want to make available
Company name, address, phone numbers tax rate.
 I build a table named tblStandard with one row only to that will hold all these information. I have these fields; Name, Address, Phone and TaxRate as just 3 examples.

I would like to write just 1 procedure using SQL statement and create 1 recordset and be able to access any field in this recordset and display them in textboxes on other forms. (I do not want to used DLookup functions).

I have created a module and write a Public Function to create the recordset.

Public Function StandardValues(ctl As Control, str As String)

    'ctl is the type of control to populate
    ' str is the name of the control


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


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

    If ctl.Name = str Then
        ctl = rst!TaxRate ' populate textbox name Tax on form
    End If


End Function


I would call the above function when I click an unbound checkbox and populate Tax textbox

Private Sub CheckBox_Click(acCheckBox, Tax)

    Call StandardValues
End Sub

I cannot get it to work and cannof find out what I am doing wrong. I am using Access 20000
Reply With Quote
  #2 (permalink)  
Old October 7th, 2003, 11:02 AM
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
  #3 (permalink)  
Old October 7th, 2003, 11:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Delete the line 'Dim intTextBoxValue As Integer'. It isn't doing anything.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i populate datagrid from a recordset object bisigreat VB How-To 1 August 6th, 2009 04:30 AM
Populate fields from drop-down selection SimonL Infopath 0 April 12th, 2007 07:30 AM
Populate a Textbox in a Formview timeware ASP.NET 2.0 Basics 0 September 29th, 2006 10:08 AM
Auto Populate fields in a form mnemec24 Access 8 March 9th, 2005 02:11 PM
How do i populate datagrid from a recordset object bisigreat BOOK: ASP.NET Website Programming Problem-Design-Solution 1 September 22nd, 2004 11:35 AM



All times are GMT -4. The time now is 07:49 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.