Insert Into Table

DBL

Registered User.
Local time
Today, 09:03
Joined
Feb 20, 2002
Messages
659
On the creation of a reconrd in the main table I'm trying to auto fill a sub table with standard information for the user. This is what I'm using to insert into the sub table:

db.Execute "INSERT INTO tblHistologySlides (HistID, HistSlide, HistEntBy) VALUES (" & Me.HistAutoNo & ", " & Me.Text58 & ", " & Me.HistEntBy & ")"

It's stepping through the code without problem but the data isn't going into the table.

Any ideas where I'm going wrong?

Thanks

D
 
What are the data types for these things? ...
Me.HistAutoNo & ", " & Me.Text58 & ", " & Me.HistEntBy
 
DBL,

You need "punctuation" in your SQL string:

Code:
db.Execute "INSERT INTO tblHistologySlides (HistID, " & _
           "                                HistSlide, " & _
           "                                HistEntBy) " & _
           "VALUES (" & Me.HistAutoNo & ", '" & _
                        Me.Text58 & "', #" & _
                        Me.HistEntBy & "#);"

You want to feed the interpreter a string like:

                       No punctuation, it's a number
                       |     Need quotes, it's a string
                       |     |           +-- Need #, it's a date
                       V     V           V
Insert Into ... Values(1234, 'YourText', #5/10/2006#);
                       ----   --------    ---------

Your variables Me.HistAutoNo, Me.Text58 and Me.HistEntBy supply the underscored values,

You have to supply the rest within your quotation marks.

Wayne
 
Thanks for the suggestions. Finally got it working, it wasn't recognising the entry on the one side of the relationship and wouldn't therefore enter the details into the many table. Used Me.requery before the code which worked.
 

Users who are viewing this thread

Back
Top Bottom