Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

access INSERT into table

Posted on 2013-01-23
5
Medium Priority
?
429 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 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 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