[RESOLVED] Method or data menber not found
Compile error:Method or data menber not found.
Any ideas what's wrong with this coding?
VB Code:
Option Explicit
Private cn As ADODB.Connection
Private rs As ADODB.Recordset
Private total4
Dim temp, mov
Dim DataMember As String
Dim Data As Object
Private Sub Form_Load()
Set cn = New ADODB.Connection
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.Open App.Path & "./Car Rental.mdb"
Set rs = New ADODB.Recordset
rs.Open "Customer", cn, adOpenStatic, adLockOptimistic, _
adCmdTable
Set Text1.DataSource = rs
Text1.DataField = "CustID"
Set Text2.DataSource = rs
Text2.DataField = "CustFname"
Set Text3.DataSource = rs
Text3.DataField = "CustLname"
Call GetDataMember
d.Caption = rs.total4 '<------- error source
End Sub
Private Sub GetDataMember()
Set Data = rs
temp = rs.RecordCount
If temp < 2 Then
mov = temp & " Customer "
Else
mov = temp & " Customers "
End If
total4 = "Total " & mov & "in the database."
End Sub
Re: Method or data menber not found
these codes are in one form??
Re: Method or data menber not found
total4 is not a member of rs, if it's a field in your table then try..
VB Code:
d.Caption = rs.Fields("total4")
Re: Method or data menber not found
Yes, you probably mixed up the short hand notation of using a period when it shold be an exclamation point.
Re: Method or data menber not found
i'll also try
VB Code:
d.Caption = rs.Fields(total4)
Re: Method or data menber not found
Sorry, i got an runtime error.
Item cannot be found in the collection corresponding to the requested name or ordinal.
VB Code:
d.Caption = rs!total4 '<---- error
Re: Method or data menber not found
Then total4 is not a field in your table or query select statement. Verify the spelling in your base table.
Re: Method or data menber not found
Re: Method or data menber not found
Doh! Its a variant variable and not a field name at all. Your setting a string to it and that string is not in your database' fields collection for your base table.
VB Code:
Private total4
'...
total4 = "Total " & mov & "in the database."
Re: Method or data menber not found
total4 is used to calculate recordcount of my records.
It just a name.
VB Code:
Private Sub GetDataMember()
Set Data = rs
temp = rs.RecordCount
If temp < 2 Then
mov = temp & " Customer "
Else
mov = temp & " Customers "
End If
total4 = "Total " & mov & "in the database."
End Sub
Re: Method or data menber not found
Quote:
Originally Posted by RobDog888
Doh! Its a variant variable and not a field name at all. Your setting a string to it and that string is not in your database' fields collection for your base table.
VB Code:
Private total4
'...
total4 = "Total " & mov & "in the database."
then what should i do?
Re: Method or data menber not found
Then it should be something like...
Re: Method or data menber not found
maybe this one might work
Re: Method or data menber not found
Quote:
Originally Posted by RobDog888
Then it should be something like...
That is the same as my original coding.
See thread 1 pls.
Re: Method or data menber not found
No its not. Check where it says "Error here"
VB Code:
d.Caption = [color=red][b]rs.[/b][/color]total4 '<------- error source
Re: Method or data menber not found
Thanks all your inputs, i got the error solved.
VB Code:
rs.Open "Customer", cn, adOpenStatic, adLockOptimistic, _
adCmdTable
VB Code:
rs.Open "Customer", cn, adOpenStatic, adLockOptimistic, adCmdTable
Is there a difference when you do the 2 coding above?
Re: Method or data menber not found
Re: Method or data menber not found
That will not create the error as its nothing more then a line continuation character. Also, if it was it would have highlighted that line instead. :D ;)
As long as its working now. :)