'Invalid use of the Dot' - but the code worked before?

kate10123

Registered User.
Local time
Today, 22:05
Joined
Jul 31, 2008
Messages
185
Hi there,

I am using the following code behind a button:

Code:
Private Sub student_Click()
Dim reportname As String
Dim DateFilter As String

reportname = listReports.Value
DoCmd.OpenReport reportname, acViewPreview, , "[Date] Between #" & Me.cboFrom & "# And #" & Me.cboTo & "#"

End Sub

This code seemed to work fine for a while and now it highlights the line
Code:
reportname= listReports.value
it does not seem like the '.'

Basically this line is saying that the item selected in the listbox is the name of the report.

Perhaps I am using .value incorrectly?
 
it should be like this
Code:
reportname= "listReports.value"
as this is a string
 
Is the the list box's "Multi Select" property set None? If not, change it to None and try again...else try the following...

reportname = cstr(listReports.Value)

Regards,
Tim
 
An exact error number or message could be useful - and if the error is raised at runtime or compilation?
(I'd guess the latter in this case).

The fact that you say this used to be working (but without any alteration?)
Is the listbox still definitely so named - and present.

I don't think it's (directly) related to the mode of the listbox (Value is always a property - the compiler can't allow for mode) and you are returning the string value from it.

It's probably form corruption for something so fundamental a property as this.
You can (and should) go about trying to clean out the form (importing all into a new MDB etc) but for now (and as a test) - the Value property is the default for a data control - so you can just omit it.
Does just
reportname = listReports
still raise an error?

Cheers
 
ok I misunderstood use this one

reportname= listReports
 
Thanks for all the replies. I had a default value which was causing the confusion. This would explain why the code was working before and not now. I have deleted this default value and it works fine now

Thanks again guys :)
 
This code seemed to work fine for a while and now it highlights the line
Code:
reportname= listReports.value
So as Pono1 has referred to - have you tried recently to set the listbox's Multi-Select property to YES? If you have then a list box then doesn't have a .Value property. If it is set to NO (only select one item) then it can have a .value property. But, if the Multi-select is set to Yes then you have to use code to iterate through the selected items.
 
The reason I didn't feel that this was related to a possible mulit-select nature of the listbox - is, as I mentioned (subtly ;-) that the Value property remains regardless of the mode of the listbox control. It just returns Null when in one of the multi-select modes.
The error here was (seemingly at the time) being raised by the presense of the Value property.

However Kate is probably currently skipping off happily over the hills - up and running... ;-) So we may never know.
But I'm not totally clear on how or what was the actual cause in the end though.
A default value shouldn't be causing a problem (certainly not at compile time) so were we, in fact, dealing with a runtime error... (though I don't see how that would then point to the code not liking the "dot").

I suppose it comes back to my first comment - detailed error descriptions are so very important. :-) That an error occured alone often tells us so very little.
 
The reason I didn't feel that this was related to a possible mulit-select nature of the listbox - is, as I mentioned (subtly ;-) that the Value property remains regardless of the mode of the listbox control. It just returns Null when in one of the multi-select modes.

Leigh:
Nevermind
 
Last edited:
lol...
>> "Nevermind"

Mum??

Ah no - that was "Never you mind". :-)
 
Unless I've missed it but nobody has pointed out that your report has a control named Date which is used in your criteria selection. The word Date is a reserved word and should be avoided.

CodeMaster::cool:
 

Users who are viewing this thread

Back
Top Bottom