Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

access INSERT into table

Posted on 2013-01-23
5
418 Views
Last Modified: 2013-01-23
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
0
Comment
Question by:topUKlawyer
  • 2
  • 2
5 Comments
 
LVL 84
ID: 38811968
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 & "')"
0
 
LVL 3

Expert Comment

by:jcrozier21
ID: 38811980
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

0
 

Author Comment

by:topUKlawyer
ID: 38812011
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 & ")"
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 38812043
CurrentDb.Execute "INSERT INTO files(fileID,clientID)VALUES(" & i & ",5)"

But I doubt the value would always be "5", so you'd need to use a variable technique as i showed earlier:

Dim myClientID As Integer

myClientID=5

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

If you're doing this from a Form, and you have selected the Client on the form, and if the form has a field namend "clientID":

myClientID = Me.clientID
0
 

Author Closing Comment

by:topUKlawyer
ID: 38812140
roger, lift off,

many many thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question