"Method or Data Member Not Found"

T

Travis Box

I have a userform that is coded to assign a value to a cell and then
call a macro. The macro then looks at that cell, and processes
several actions on several different sheets, whose sheet names are
based around the value intially set by the code in the userform. This
allows me to have several different buttons on the userform who all
call the same macro, but who all get the macro to do things on several
different sheets based on what value they assign to a cell. It also
allows me to save the workbook and come back later for more processing
with the value still assigned to the cell. For example::

Button 1 click event on the userform assigns the value "1" to a cell
then calls MacroA:::
MacroA takes the value "1" from the cell and processes;
Sheet "Day 1"
Sheet "Export 1"
Sheet "Report 11"

Button 2 click event on the userform assigns the value "2" to a cell
then calls MacroA:::
MacroA takes the value "2" from the cell and processes;
Sheet "Day 2"
Sheet "Export 2"
Sheet "Report 12"

Once each button is successfully processed, and only if it is
successfully processed, I want the MacroA to be able to change the
caption value, disable the button that was pressed and change it's
background color. Inside MacroA I'm trying to place a "With"
statement that can be used to make the necessary changes to the button
on the userform. The way I do that is to assign a string value that
is based on an initial text string combined with the value that was
pulled from the cell, and then placing that ionto the "With" statement
as a replacement for the actual button name. This first line of this
that the compiler comes to is what is giving me the "Method or Data
Member Not Found" error message, and it's highlighting the string
variable in the first line of the "With" statement. The code look
like this.....
Things you should know first:
userform = "frmProcessCreditAudit"
button on the userform = "ProcessDay1"
value of intDayNumber that was pulled initial from the cell = 1

Code:

Dim strFormButton As String
strFormButton = "ProcessDay" & intDayNumber
With frmProcessCreditAudit
frmProcessCreditAudit.strFormButton.Caption = "Day " &
intDayNumber & " Processed"
frmProcessCreditAudit.strFormButton.Enabled = False
frmProcessCreditAudit.strFormButton.BackColor = &H0&
End With


does anyone have any ideas as to how I can code this in a method that
will work or what exactly it is that I'm doing wrong? Any help would
be greatly appreciated. Thanks!
 
B

Bernie Deitrick

Travis,

Your variable strFormButton contains the name, so instead of code like

frmProcessCreditAudit.strFormButton.Caption

use code like

frmProcessCreditAudit.Controls(strFormButton).Caption

HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top