Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving field names as strings 1

Status
Not open for further replies.

marduk813

Programmer
Jul 18, 2002
89
US
what i'm trying to do is combine several virtually identical functions into one, and use a Select Case statement to differentiate the buttons that will be clicked. i've done it once already and it works perfectly. now the issue i'm having is with saving a field name and property (i.e. txtRDoc1Date.Value) as a string variable for use in comparisons later in the function. is this possible? what i have now is this:

Code:
Private Function DateButtonHandler(intButton as Integer)

Dim strReceivedDocDate as String
Dim strSentDocDate as String

Select Case (intButton)

     Case 1: strReceivedDocDate = "txtRDoc1Date.Value"
             strSentDocDate = "txtSDoc1Date.Value"
     Case 2:
        |
        |
     Case 6: etc, etc.

End Select

If (IsNull(strReceivedDocDate) = True) Then
     --fill in fields here--
End If

the code above does not seem to work. i'm guessing it's because i can't store "txtRDoc1Date.Value" as a string and still have it function as if it were an object and a property. can anyone shed some light on this?

thanks in advance,
jas
 
Not sure what you're trying to do, but if you are trying to assign the value of your date textbox as a string, and need to capture special cases, you could use something like

strReceivedDocDate = iif(isnull(txtRDoc1Date.Value),"NULL", _
format(txtRDoc1Date.value,"yyyy-mm-dd")

That's just an example of course, but now you can check if the STRING value is equal to "NULL".

Rob
[flowerface]
 
You need to save the entire object as a control object

Private Function DateButtonHandler(intButton as Integer)

Dim strReceivedDocDate as String
Dim strSentDocDate as String
dim Recievecontrol as control
dim Sendcontrol as control
Select Case (intButton)

Case 1: Recievecontrol = txtRDoc1Date
Sendcontrol = txtSDoc1Date
Case 2:
|
|
Case 6: etc, etc.

End Select

If (IsNull(strReceivedDocDate) = True) Then
--fill in fields here--
End If


you can then use the code defined controls and access them in exactly the same as you could a design time defined control
 
rob, thanks for the reply, but kylua had the answer i needed.
now kylua, i have a question. i've modified my code so that it uses control objects, but whenever i click the button on my form that should activate this function, i get the message:

The expression On Click you entered as the event property setting produced the following error: Object variable or With block variable not set.


i'm a little confused by this as i've set up this button handler function the same way i set up a previous one, and the previous one works fine. my code now looks like this (with a few name changes as well):

Code:
Private Function DateMatchHandler(intButton As Integer)

    Dim ctlReceived As Control
    Dim ctlSent As Control
    
    Select Case (intButton)
    
        Case 1: ctlReceived = txtRUQADate
                ctlSent = txtSUQADate
                
    End Select
    
    If (ctlReceived.Value = &quot;&quot;) And (ctlSent.Value <> &quot;&quot;) Then
        ctlReceived.Value = ctlSent.Value
    ElseIf (ctlReceived.vale = &quot;&quot;) And (ctlSent.Value = &quot;&quot;) Then
        ctlReceived.Value = FormatDateTime(Date, vbShortDate)
        ctlSent.Value = FormatDateTime(Date, vbShortDate)
    Else
        ctlSent.Value = ctlReceived.Value
    End If

End Function

i tried using the IsNull function on the control objects, but it didn't seem to help. any idea what i'm doing wrong here?
 
Am I right in assuming that you have the button events as:

sub commandbutton1_click()
call datematchhandler(1)
end sub

sub commandbutton2_click()
call datematchhandler(2)
end sub

sub commandbutton3_click()
call datematchhandler(3)
end sub

Does the error occur in these subs or when the function is called. If it occurs in the function, at what point?
 
actually, my button event is (on the On Click line): &quot;=DateMatchHandler(1)&quot;
this method worked great for another button handler i use.
i've narrowed the problem down to the Select Case area.
to be specific, the two lines

Code:
ctlReceived = txtRUQADate
ctlSent = txtSUQADate

are where the problem exists. i'm not sure why there's a problem there, since the VBA help section seems to indicate that i'm using the control type correctly.
 
Try removing the dim statement for the control variables so that it will accept anything. (or if your using option explicit, dim as variant) Then see if there is a value after the assignment in those lines. If it is &quot;&quot; then the definition of txtRUQADate is lacking. Is this function in a module or in the code window for the form. If it is in a module then try:
userform1.txtRUQADate

If none of that works, send the lot to colin@kylua.com cos I'm getting to the stage that I want to sort this out.
 
eureka!

after doing more searching, i realized i was missing a tiny little thing: &quot;Set&quot;

this code works

Code:
Set ctlReceived = txtRUQADate
Set ctlSent = txtSUQADate

specifically, the page that helped was

now i am free to continue my programming until tomorrow, when i'm sure i will encounter yet another obstacle that i cannot overcome without asking people smarter than me for help :)
thank you very much for your help, kylua!
 
You know what, I keep missing that as well. Glad I could help, (star would be nice :))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top