Solved

access INSERT into table

Posted on 2013-01-23
5
421 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 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 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