Not saving to table using addNew

smelly

Registered User.
Local time
Today, 18:02
Joined
May 23, 2002
Messages
44
I am new to VB and am having some problems. I am trying to save data into a table from a form. I am getting an error message "can't find the field '|' referred to in your expression" and it refers to the line that reads Table1a.AddNew.
Thanks! (This is my first encounter with both Access and VB)

Private Sub checkbox1_Exit(Cancel As Integer)
Dim BBCNum As Long
If Me.[checkbox1] = True And Me.MATRIX <> Aq Or CT = True Then
BBCNum = Me.BBCID
DoCmd.OpenTable "Table1a", acViewNormal
Table1a.AddNew
Table1a![LAB ID] = BBCNum
Table1a.Update
Table1a.Close
End If
End Sub


Thank you for any help!
 
Last edited:
Are you trying to add a new record to a table or update one? Is the form that holds the code listed in you post bound to the table you want to update?
A bit more info on your direction and I am sure that any number of forum members could help out....
Chris
 
I am trying to add a new record to the table and the form is not bound to the table.
Thanks!
 
In your code is this line
<<
Table1a.AddNew
>>

You are telling Access to use the AddNew method on object "Table1a".

Where is the object "Table1a" ? Trick question :) It's nowhere.

See Help/Find for 'DAO'.

RichM
 
Why not continue with the previous thread so members aren't wasting their time guessing
 
The easiest way I know to add records to an unbound table is using DoCmd.RunSql and provide the INSERT string that suits you needs.


Here is you original code...

Dim BBCNum As Long
If Me.[checkbox1] = True And Me.MATRIX <> Aq Or CT = True Then
BBCNum = Me.BBCID
DoCmd.OpenTable "Table1a", acViewNormal
Table1a.AddNew
Table1a![LAB ID] = BBCNum
Table1a.Update
Table1a.Close
End If
End Sub


Changed it to this ...

On Error GoTo ErrHandler

Dim BBCNum As Long

If Me.[checkbox1] = True And Me.MATRIX <> Aq Or CT = True Then
BBCNum = Me.BBCID

DoCmd.SetWarnings False
DoCmd.RunSql "INSERT INTO Table1a ([Lab ID]) VALUES ( " _
& BBCNum & ");"

End If

ExitLabel:

DoCmd.SetWarnings True
Exit Sub

ErrHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ExitLabel

End Sub

.... Keep in mind that you should try to insert a viable record into Table1a. It should be as complete as possible...Also I assume that your BBCNum variable holds a number. If it holds a string you need to change the INSERT to...


DoCmd.RunSql "INSERT INTO Table1a ([Lab ID]) VALUES ( ' " _
& BBCNum & " ');"

HTH
Chris
 
THANK YOU!

It is working!!!!!! Thank you so much for your help and patience!
 

Users who are viewing this thread

Back
Top Bottom