quick key violation error

swarv

Registered User.
Local time
Today, 01:12
Joined
Dec 2, 2008
Messages
196
I have the following code:

Code:
Dim bradfordscore As Long
bradfordscore = Me.Text141
    SQLText = "INSERT INTO tbl_users ([bradfordscore]) SELECT " & bradfordscore & ""
    DoCmd.RunSQL SQLText

Can anybody see why it is coming up with 1 key violation error when run?
Thanks
Martin


p.s. bradfordscore is a number.
 
A key violation would imply that the number already exists in the table, and that field doesn't allow duplicates.
 
The field has just been created as a normal text field. so all the boxes are empty. i.e. I have a name field, date field etc... and also a bradfordscore field.

Any ideas?
 
I believe you also need quotes if the field is a text field.
Code:
SQLText = "INSERT INTO tbl_users ([bradfordscore]) SELECT '" & bradfordscore & "'"
 
I have the following code:

Code:
Dim bradfordscore As Long
bradfordscore = Me.Text141
    SQLText = "INSERT INTO tbl_users ([bradfordscore]) [COLOR=red][B]SELECT " & bradfordscore & "" { FROM SomeTable? }[/B][/COLOR]
    DoCmd.RunSQL SQLText

Can anybody see why it is coming up with 1 key violation error when run?
Thanks
Martin


p.s. bradfordscore is a number.

The field has just been created as a normal text field. so all the boxes are empty. i.e. I have a name field, date field etc... and also a bradfordscore field.

Any ideas?





Two observations:
  1. Is the SQL Statement Complete? It looks like it is missing a FROM Clause in the SubQuery (see RED above).
  2. Is tbl_users.[bradfordscore] a Text Field and the valuie from (1) a Number? (See GREEN above).
 
many thanks to all your answers. I used update and SET. my fault I know. thanks anyway
 

Users who are viewing this thread

Back
Top Bottom