Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 29th, 2006, 11:42 PM
Authorized User
 
Join Date: Oct 2006
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I 'Set an obj reference using a variable?

I have several unbound comboboxes bound with names cboC1, cboC2, cboC3 ... cboC119, cboC120.

After update any individual combo box will pass its value into its respective bound textboxes C1, C2, C3 .... C119, C120

The event handler would be the same for all 120 comboboxes, so I wanted to create two object variables as follows:

Dim cboC As ComboBox
Dim txtC As TextBox

Then I want to set the value of the objects to the firing combobox and its associated textbox (sort of as follows):

Private Sub cboC1_AfterUpdate()
     cboSelectCustomer(cboC1.Name)
End Sub

Private Sub cboSelectCustomer(cbo as combobox)
Set cboC=cbo
Set txtC=Eval("C" & Right(cboC.name,len(cboC.name)-4)

If cboC <> " None" Then txtC = cboC Else txtC = Null
    txtC.SetFocus
    cboC.Visible = False
End Sub

In the first 'Set' command I am trying to pass in cboC1 as variable cboC. It doesn't work, Object required (Error 424)
 ( Can someone tell me how to make that work?

In the second 'Set' command I am to strip the '1' off the right end of cboC1 and then combine it with C to try to form the name of the object textbox 'C1', which is the name of the text box that I will pass the value into.

Unfortunately that doesn't work either. Eval results in a string and I have tried a variety of things but can't seem to get it.
(Can someone tell me how to make that work?)

The following does work, but if requires that I set the object variables all individually, so its a lot more redundancy of code:

Private Sub cboC1_AfterUpdate()
        Set cboC = cboC1
        Set txtC = C1
        cboSelectCustomer
End Sub


Private Sub cboSelectCustomer()
    If cboC <> " None" Then txtC = cboC Else txtC = Null
    txtC.SetFocus
    cboC.Visible = False
End Sub

My idea is to get the AfterUpdate events to be as short as possible, 1 line if possible, and have all the code in the cboSelectCustomer sub, then I have one place to manage the code for all 120 comboboxes and all 120 textboxes.

I hope I made the problem clear ... your help is appreciated.










 
Old October 30th, 2006, 01:39 PM
Authorized User
 
Join Date: Oct 2006
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As it turns out I created a separate sub that has passed to it the 3 fields as text boxes, and that works, enabling me to get the initial event down to 1 line:

Dim txtTPC As TextBox
Dim txtTP As TextBox
Dim txtP As TextBox

Private Sub P1_AfterUpdate()
     Call PalletCountProcedure2(TP1, P1, Forms!fOD.sfT1!tPC1)
End Sub

Private Sub PalletCountProcedure(txtTP, txtP, txtTPC)
Me.Refresh
txtTP.Value = PalletCountForColumn(txtP.Name, Oid)
    If IsNull(txtTPC) Then
            txtTPC = 0
            txtTPC.BackColor = red
        Else
            txtTPC.BackColor = green
    End If

    If txtTP < txtTPC.Value Then
            txtTP.BackColor = yellow
        ElseIf txtTP > txtTPC.Value Then
            txtTP.BackColor = red
        ElseIf txtTP = txtTPC.Value Then
            If txtTP = 0 Then txtTP.BackColor = grey Else txtTP.BackColor = green
    End If

End Sub

Would still be interested in how to pass in an object reference as a concatenated string though.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Object refrence not set to an instance of an obj viral648 ASP.NET 1.0 and 1.1 Professional 1 January 2nd, 2007 01:11 PM
Object Variable or With Block Variable Not Set Iashia06 Access 1 May 22nd, 2006 10:24 AM
Object reference not set to an instance of an obj nrathod_97 BOOK: Beginning VB.NET Databases 4 June 21st, 2005 06:35 PM
Object reference not set to an instance of an obj. Dwizz VB.NET 2002/2003 Basics 8 June 1st, 2005 08:28 AM
Object variable or With block variable not set tparrish Classic ASP Databases 0 May 21st, 2005 06:48 AM





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