Help with an unbounded textbox

  • Thread starter Thread starter Laura
  • Start date Start date
L

Laura

Ok, this is what I have. I have a form that is based off of a query.
The form has four textboxes and a button. Three of these textboxes
have information from the query. the fourth one I want to be able to
put information into, then when you click the button it takes the
information from those textboxes and put them into a seperate table.
I am an idiot and cant figure this out on my own, please help me.

Thank you so very much,
Laura
 
In the command.click event handler, compose a SQL string to
insert a record into your second table using the values
from the 4 text boxes, then using DoCmd.RunSQL to action it

Hope That Helps
Gerald Stanley MCSD
 
I have never really used SQL before. Last night while waiting for
replies, which thank you by the way for replying, I came up with this
macro. When I click the button to run the macro I get this error "You
can't go to the specified record". I now all the names are spelled
correctly. What am I doing wrong? Is there an easier way to do this?
Thank you for all you help,
Laura

Private Sub Command11_Click()
On Error GoTo Err_Command11_Click

DoCmd.GoToRecord , , acNewRec
Dim db As Database
Dim rs As Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("scrap")
rs.AddNew
rs![scrap]![partnumber] = Forms![toscrap]![Partnum]
rs![scrap]![date] = date
rs![scrap]![scraped] = Forms![toscrap]![Text5]
rs.Update
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub
 
Laura

I am not sure why you put the DoCmd.GotoRecord command in
and your code may work with it removed.

Here is what I had in mind, based on the column names in
your code

Private Sub Command11_Click()
Dim strSQL As String
On Error GoTo Err_Command11_Click

strSQL = "INSERT INTO scrap (partNumber, [date] ,scraped)
VALUES ('" & Partnum.Value & "',#" & Date & "#,'" &
Text5.value & "');"

DoCmd.RunSQL strSQL

Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub

Note that it is not a good idea to have a column called
'date' as date is a reserved word.

Hope That Helps
Gerald Stanley MCSD
 
Back
Top