How do I copy data from a form to a table?

YuvalH

New member
Local time
Tomorrow, 00:00
Joined
Jan 21, 2022
Messages
13
I'm trying to copy the data from my form to my table. I wrote this code. and when I'm activating it an error '3061' pops.
Code:
[
Private Sub ADD_Click()
    CurrentDb.Execute "INSERT INTO MAIN(File_Name, File_Type) VALUES('" & File_Name & "', " & File_Type & ")"
    Main2.Form.Requery
End Sub
]
EDITED BY THE_DOC_MAN to insert CODE tags; no other changes

the form:
צילום מסך 2022-01-27 181358.png
צילום מסך 2022-01-27 181437.png
thx for the help
 
Last edited by a moderator:
Error "3061" is "Too few parameters." I suspect the File_Type should be quoted in the same way as you did for File_Name, with the apostrophe to enclose the substituted string.
 
Why not use a bound form? :(
 
Why not simply base the form on the table itself?
 
Error "3061" is "Too few parameters." I suspect the File_Type should be quoted in the same way as you did for File_Name, with the apostrophe to enclose the substituted string.
Didn't work
 
Try:

CurrentDb.Execute "INSERT INTO MAIN(File_Name, File_Type) VALUES('" & Me.File_Name & "', '" & Me.File_Type & "')"

InStrRev is not available to table Calculated field. However, if you can do that string manipulation in textbox, should be able to do in query.
 
Last edited:
How do you add new records to the form? In the AfterUpdate event of the file textbox update the two fields (FileName and FIleType):
Code:
Me.FileName=Mid([File].....'copy the expression you currently have in the control source property
Me.FileType=Right([File].....'copy the expression you currently have in the control source property
And make the two texboxes bound to the corresponding fields as the others suggested; no need for a separate Insert....

Cheers,
 
may be as simple as you are missing single quotes around file_type

VALUES('" & File_Name & "', " & File_Type & ")"

edit - already suggested by Doc and June
 
Try:

CurrentDb.Execute "INSERT INTO MAIN(File_Name, File_Type) VALUES('" & Me.File_Name & "', '" & Me.File_Type & "')"

InStrRev is not available to table Calculated field. However, if you can do that string manipulation in textbox, should be able to do in query.
It worked but there is a problem.
It puts the file name and type one row beneath where its soposed to be
1643359117285.png
 
Maybe don't even need SQL at all. If you want to populate fields of current record on form, simply:

Me!File_Name = Me.File_Name
Me!File_Type = Me.File_Type

The real trick is figuring out what event to put code in. Maybe form BeforeUpdate.
 
Last edited:
See post # 9 where I suggested to use the AfterUpdate event of the File textbox....
 

Users who are viewing this thread

Back
Top Bottom