Solved

access INSERT into table

Posted on 2013-01-23
5
423 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
[X]
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
  • 2
  • 2
5 Comments
 
LVL 85
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 85

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

726 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