Compile Error: Invalid Qualifier

G

Guest

Can someone please tell me wut I am doing wrong... :/

I get "Compile Error: Invalid Qualifier" whenever I run the following code:

Private Sub add_customer_Click() <<<<Debugger highlights this yellow<<<<<<
Dim db As DAO.Database
Dim rctCustomersAdd As DAO.Recordset

'*** Create a pointer to the database and a pointer to the table ***
Set db = CurrentDb()
Set rctCustomersAdd = db.OpenRecordset("tblCustomers", dbOpenTable)

' ***************************************Validate the Name field***
If IsNull(name) Or Len(name) = 0 Then
MsgBox "Please Enter a Name"
name.SetFocus <<<<<<<Also "name" is highlighted<<<<<<<<<<<<<
rctCustomersAdd.Close
db.Close
Exit Sub
End If
 
D

Dirk Goldgar

RIP said:
Can someone please tell me wut I am doing wrong... :/

I get "Compile Error: Invalid Qualifier" whenever I run the following
code:

Private Sub add_customer_Click() <<<<Debugger highlights this
yellow<<<<<< Dim db As DAO.Database
Dim rctCustomersAdd As DAO.Recordset

'*** Create a pointer to the database and a pointer to the table ***
Set db = CurrentDb()
Set rctCustomersAdd = db.OpenRecordset("tblCustomers", dbOpenTable)

' ***************************************Validate the Name field***
If IsNull(name) Or Len(name) = 0 Then
MsgBox "Please Enter a Name"
name.SetFocus <<<<<<<Also "name" is
highlighted<<<<<<<<<<<<< rctCustomersAdd.Close
db.Close
Exit Sub
End If

I take it that "name" is the name of a control on the form? The problem
is probably that Name is also a property of the form, so it's easy for
the VBA compiler to be confused as to which of these you mean. "Name"
is not a good name for a field or control, because almost every object
has a Name property. You should try to avoid the use of reserved words
for objects you define.

It would be a good idea to rename this field and control, to save
yourself trouble like this in the future. If you don't want to, though,
can probably fix your problem by explicitly qualifying it, like this:

If IsNull(Me!name) Or Len(Me!name) = 0 Then
MsgBox "Please Enter a Name"
Me!name.SetFocus
' ...

Usually you can use the "Me.name" as easily as "Me!name" in referring to
the control, but in this case you can't, because "Me.Name" is explicitly
a reference to the form's Name property.
 
G

Guest

That did it!!!! Thankx Dirk :)

Dirk Goldgar said:
I take it that "name" is the name of a control on the form? The problem
is probably that Name is also a property of the form, so it's easy for
the VBA compiler to be confused as to which of these you mean. "Name"
is not a good name for a field or control, because almost every object
has a Name property. You should try to avoid the use of reserved words
for objects you define.

It would be a good idea to rename this field and control, to save
yourself trouble like this in the future. If you don't want to, though,
can probably fix your problem by explicitly qualifying it, like this:

If IsNull(Me!name) Or Len(Me!name) = 0 Then
MsgBox "Please Enter a Name"
Me!name.SetFocus
' ...

Usually you can use the "Me.name" as easily as "Me!name" in referring to
the control, but in this case you can't, because "Me.Name" is explicitly
a reference to the form's Name property.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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