views:

196

answers:

2

So I have an input form that I want to use to update a table with certain fields of information. I have the ID of the record automatically coming up in a text box. I have three text boxes that I need to add to the table (excluding the ID) on a button click.

Name Date Method

are the field names.

As_Name As_Date As_Method

are the text box names

The table name is POC, and the ID is "POC_ID" (its an autonumber).

So I do not want these objects (text boxes) to be bound to the table because this is a little separate "pop-up" form that comes from a form that the table, and I only want the input to be relative to the POC_ID that is already selected via the original form.

So how do I write the vba for this to 1)check to make sure that records do not already exist....2)update the fields (listed above) with data input from the text boxes(listed above). I want to be able to use this with a button click....

please help!!

EDIT:

actually it is one table not two; i have two forms that I want to be able to send information to the same table (different information though). this db was already built by someone else and know I have been deamed to take it over.

I need to add a second little pop up form for additional information to be added based on new requirements (there is literally no where for me to place this on the other one). I have already done that, and used a suggested object approach to reference the first forms (from which this second "pop-up" form springs from) to add the relative id fields. Now I have this second little pop up form that just asked three values to be inputted (which are the ones listed above).

I just simply do not know how to link the text box, with a field so that once a user enters in the information, clicks "save" it saves the information to the table relative to the TripID that is there (one mentioned above). the only way I know how to get the text boxes to save data to the table is to use the builder/wizard when I create a new one.

I would like to learn how to link an object (text box, cmb, list) etc on a form, to a table with an "On Click" method so that I can use a save button. Basically that is it!

+1  A: 

The OpenForm method of DoCmd allows for several arguments, including Where and Openargs. You can take advantage of these.

However, something seems to be quite wrong with your table design in that you appear to be holding the same information in two tables and for no stated reason. Have you read http://www.r937.com/relational.html?

I would suggest that the design you need probably only includes a numeric field POC_ID that is a foreign key to the main table.

Remou
+1  A: 

Still not sure I understand your situation, but let me offer the outline of an answer. If my outline is not close enough, please explain where I went astray.

Your parent form, frmParent, has a command button (cmdMoreFields) which opens the child form (frmChild) where you will enter values for 3 additional fields in the record currently displayed in frmParent. After the user enters those values in frmChild (in text box controls named As_Name, As_Date, and As_Method), she will click a command button (cmdSave) to store those values to fields (Name, Date, and Method) in table POC, and close frmChild. Also, frmParent includes a text box (txtPk_field) which holds the value for the primary key (field pk_field in table POC) of the current record.

However, I'm not sure which field/control you're using for txtPk_field, and doubt that value is available if the the current record has not yet been saved. So, I'll suggest this code for the cmdMoreFields "on click" event:

If Me.Dirty Then Me.Dirty = False
DoCmd.OpenForm "frmChild"

In the "on click" event of cmdSave (on frmChild), try code similar to:

Dim strSql As String
strSQL = "UPDATE POC SET [Name] = """ & Me.As_Name & """, [Date] =#" _
    & Me.As_Date & "#, Method = """ & Me.As_Method & """ WHERE pk_field = " _
    & Forms!frmParent.txtPk_field & ";"
Debug.Print strSql
CurrentDb.Execute strSql, dbFailOnError
DoCmd.Close

If that approach works, consider passing the pk_field value to frmChild with Openargs, as Remou suggested.

Note: I assumed the data type for Name is text, Date is date/time, and Method is text. You will have to change the UPDATE statement delimiters for any fields whose data types differ from my guesses.

HansUp
thanks so much HansUp!! i appreciate you stickin with my bad explaination because I believe this is exactly what I was looking for!! I really appreciate it!
Justin
actually i was setting the new form up likeOption Explicitdim PreviousForm as frmParent (as you put it)set PreviousForm = forms!frmParentme.POC_ID = PreviousForm.POC_IDand this was carrying over the ID number into a text box for me fine. I just did not know the SQL to insert the information from the next text boxes into the table specifically for this ID#can't wait to get to work (relative) to try this out! appreciate it!
Justin