Connecting Tech Pros Worldwide Help | Site Map

INSERT INTO - method or data member not found

Newbie
 
Join Date: May 2007
Posts: 2
#1: May 30 '08
I am hoping someone can help me as I've done this sort of thing before with no problems. I am using Access 2003 SP2 on WinXP prof SP2

I have an unbound form (single form view) with 18 unbound text controls and a command button. I am trying to have this code on 'On Click' Event of the button to insert the data into a table (which has an autonumber PK)

Expand|Select|Wrap|Line Numbers
  1. Dim sSQL As String
  2.     sSQL = " INSERT INTO tbl_ScribalMain " & _
  3.     "(CompName, ContactName, [Position], DelAddress1, DelAddress2, DelTown, DelPCode, Country, Phone, Fax, Mobile, Email, [Website], BusinessType, [Group], ABN, Notes, [ReSubCalls-Comments])" & _
  4.     "VALUES('" & Me.txtCompName & "', '" & Me.txtContactName & "', '" & Me.txtPosition & "', '" & Me.txtAddress1 & "', " & _
  5.     "'" & Me.txtAddress2 & "', '" & Me.txtTown & "', '" & Me.txtPCode & "', " & _
  6.     "'" & Me.txtCountry & "', '" & Me.txtPhone & "', '" & Me.txtFax & "', '" & Me.txtMobile & "', '" & Me.txtEmail & "', " & _
  7.     "'" & Me.txtWebsite & "', '" & Me.txtBusType & "', '" & Me.txtGroup & "', '" & Me.txtABN & "', " & _
  8.     "'" & Me.txtBusNotes & "', '" & Me.txtComments & "');"
  9.  
  10.     DoCmd.RunSQL sSQL
I am receiving a 'method or data member not found' error when I try to compile or run the code. The highlighted member is Me.txtWebsite
It is spelled correctly
I initially tried it without the "Dim sSQL As String", just going "DoCmd.RunSQL etc, but it didn't make any difference.
The thing that kills me is that this is my second attempt.
On my first attempt I used a form that was bound to the Table and the text controls were bound to their respective fields in the table. I removed the 'Control Source' from all fields and the form, making it unbound and had the same problem but with Me.txtPosition which is third VALUE parameter in code.
To make sure there wasnt something strange coming across with old form I started from scratch with a brand new, unbound form and created and named all the fields, and now the error is on Me.txtWebsite which is the tenth VALUE parameter in the code.
I have check all the spellings over and over. I have made sure that the code is in the same order that the fields appear on the table.
Any help at all with this would be greatly appreciated as I am running out of hair to pull out.
Thanks in advance.
Moderator
 
Join Date: Feb 2008
Location: Beauly, near Inverness, Scotland
Posts: 1,576
#2: May 30 '08

re: INSERT INTO - method or data member not found


Hi. Your code seems OK, at least syntactically. The error message is telling you that there is apparently no control of the name given, txtWebsite, on that form, even though you have checked the spelling and so on.

Given that you have been using unbound controls for some reason I am sure you are aware that the names you are referring to in the Values section of the SQL are of the controls on the form, not the fields in the table. The control's name as used on the form must be what you refer to in the code.

I would check that the control is indeed named txtWebsite and not, say txtWeb Site which you would have to refer to within brackets, or txtWebsite_ (where the underscore means an extra space). Although you are using the dot property form of the Me reference this should not make a difference here (the normal form of control reference uses Me![Control Name], or Me!ControlName if without spaces).

The VB editor should be able to help you as it will show you all the properties and control names of the form after you type me. You can scroll the list of controls/properties and check what the actual name of the control is - the list will mostly show underscores in place of any spaces in the names listed (although I have also seen the list show bracketed names with spaces in this circumstance).

Let us know how you get on.

-Stewart
Reply