How do I copy data from a form to a table? (1 Viewer)

YuvalH

New member
Local time
Today, 12:13
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:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:13
Joined
Feb 28, 2001
Messages
27,148
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.
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:13
Joined
Sep 21, 2011
Messages
14,238
Why not use a bound form? :(
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 05:13
Joined
Apr 27, 2015
Messages
6,321
Why not simply base the form on the table itself?
 

YuvalH

New member
Local time
Today, 12:13
Joined
Jan 21, 2022
Messages
13
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
 

June7

AWF VIP
Local time
Today, 01:13
Joined
Mar 9, 2014
Messages
5,466
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:

bastanu

AWF VIP
Local time
Today, 02:13
Joined
Apr 13, 2010
Messages
1,402
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,
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:13
Joined
Feb 19, 2013
Messages
16,610
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
 

YuvalH

New member
Local time
Today, 12:13
Joined
Jan 21, 2022
Messages
13
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
 

June7

AWF VIP
Local time
Today, 01:13
Joined
Mar 9, 2014
Messages
5,466
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:

bastanu

AWF VIP
Local time
Today, 02:13
Joined
Apr 13, 2010
Messages
1,402
See post # 9 where I suggested to use the AfterUpdate event of the File textbox....
 

Users who are viewing this thread

Top Bottom