Link to home
Start Free TrialLog in
Avatar of Richard
Richard

asked on

access INSERT into table

Private Sub Command397_Click()

Dim i As Integer


 For i = Me.clientOneMobile To Me.clientTwoMobile

 CurrentDb.Execute "INSERT INTO files(fileID)VALUES(" & i & ")"

Next i

End Sub

This is code which Inserts new records into Table called Files.

There is also a related table Clients.

Clients is the One and Files is the many.

How do I adapt the code to proi=vide new records for a specific Client, say, who has an ID of 5 (by way of unique index)

 A WHERE addition to the code above?
Please help
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Does the "files" table include a field named "ClientID", or something of that nature? If so,  you'd do this:

CurrentDb.Execute "INSERT INTO files(fileID, ClientID )VALUES(" & i & "," & MyClientID & ")"

If "ClienttID" is a text field, you'd have to do this:

CurrentDb.Execute "INSERT INTO files(fileID, ClientID )VALUES(" & i & ",'" & MyClientID & "')"
Unless I'm reading it wrong, simply:
CurrentDb.Execute "INSERT INTO files(fileID)VALUES(5);"

Open in new window

or
Dim foo as Integer
foo = 5
CurrentDb.Execute "INSERT INTO files(fileID)VALUES(" & foo & ");"

Open in new window

Avatar of Richard
Richard

ASKER

it is  a number field...

this puts the new file records in but not the client number 5 in those records

any clues?

CurrentDb.Execute "INSERT INTO files(fileID,clientID)VALUES(" & i & "," & 5 & ")"
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richard

ASKER

roger, lift off,

many many thanks