Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form wont save item into table. 2

Status
Not open for further replies.

Acipenser

Technical User
Oct 15, 2001
39
US
I have a form (let's call form 2) in which one of the fields data is taken from a previous form (let's call form 1). When form 2 opens the correct information is in the field, but when the form is closed it is not saved to the table connected to form 2. All the other information entered into form 2 is saved correctly. What needs to be done to save the looked up information in the table?
 
You said the info displays correctly in form 2. Is the textbox that the info is in bound to a field in the table you want the info saved to?

All info in a form will be pulled from/saved to the field in the Control source property.

Hope that helps. Maq B-)
<insert witty signature here>
 
The current form is frmMorpho. It's record source is tblMorphometrics. The control source for the text box is =[Forms]![frmCollectionInfo]![FishID]. This gets the information from the previous form &quot;Collection Info&quot;. I have a field in tblMorphometrics called FishID, but nothing gets saved to it. All the other information entered into frmMorpho is saved correctly in tblMorphometrics. Is that any clearer? What is wrong?
 
The control source for this field needs to be the field that you want it saved to. Since your control source is the previous form, Access doesn't know to save it to tblMorphometrics.

Change the control source to FishID (Assuming that is the field name in your table) and put this code in the on open or on current event of form2 (whichever is appropiate for you.)

me!fishtextboxname = =[Forms]![frmCollectionInfo]![FishID] Maq B-)
<insert witty signature here>
 
oops sorry, only 1 equal sign. Maq B-)
<insert witty signature here>
 
I tried that but got a Error 2448.
I put the following code in under &quot;on open&quot; for the form:
Private Sub Form_Open(Cancel As Integer)
Me![FishID] = [Forms]![frmCollectionInfo]![FishID]
End Sub

Does it matter that frmMorpho is linked to frmCollecitonInfo by this code on the Open button:

Private Sub butMorpho_Click()
On Error GoTo Err_butMorpho_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = &quot;frmMorpho&quot;
stLinkCriteria = &quot;[FishID]=&quot; & &quot;'&quot; & Me![FishID] & &quot;'&quot;
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_butMorpho_Click:
Exit Sub
Err_butMorpho_Click:
MsgBox Err.Description
Resume Exit_butMorpho_Click
End Sub

And also when I look at frmMorpho it has [FishID] = &quot;the correct number&quot; under Filter: in the properties lists.

????????

Thanks for your help.
 
Ok, I'm confused now. Since the forms are linked on this field and it apparently is bringing up the correct record then the fishid must already be stored in the underlying table.

All you really need to do is make sure the field is bound to the field in the table. I thought you needed to actually update an empty field. Delete the code in the on open event that I mentioned earlier.


Oh, and I don't know what an error 2448 is. Maq B-)
<insert witty signature here>
 
OK - Lets do this another way. Start from scratch.

I have frmCollectionInfo that allows a user to type in a FishID. There is a button on frmCollectionInfo to open frmMorpho. I want frmMorpho to open and display the FishID entered in frmCollectionInfo. The user then enters information in frmMorpho and that information as well as FishID are saved in tblMorphometrics when the form is closed. The FishID is also saved in tblCollectionInfo (that part works).

How do I do that?

Thanks
 
Ok, form morpho should have tblMorphometrics (where did that name come from?) as its recordsource and each textbox should be bound to a field in tblMorphometrics.

Form Collection info should be either unbound or bound to tblCollectioninfo depending on how it's being used. Is this form used to enter and store new info into the collections or is it simply a pop-up form only used to get to the morpho form?

Here's the code I would put in the click event of the button used to open morpho. (Not sure if this is the absolute best way to do this or not. If anyone else has a better idea, please speak up. I'm floundering here!)

Dim Criteria as string
Dim NumRecs as integer

Criteria = &quot;[FishID] = &quot; & me!fishid
NumRecs = Dcount(&quot;*&quot;,&quot;tblMorphometrics&quot;,Criteria)
If NumRecs > 0 then
docmd.openform &quot;frmMorpho&quot;,,,Criteria
else
docmd.openform &quot;frmMorpho&quot;,,,,acFormAdd
[Forms]![frmMorpho]![FishID] = FishID
end if


I haven't tried this, so not sure if the [forms]!... assignment will cause an error or not. Maq B-)
<insert witty signature here>
 
Well. I saw what you wrote. And that looked extremely complicated, but it did remind me of something. I know I have similar forms in this database that did the same thing, but worked. I went back and looked at the code for the button that opens those forms. I had forgotten to include 2 lines of code on this form. The code is:

DoCmd.GoToRecord , , acNewRecord
Forms![frmMorpho]![FishID] = Forms![CollectionInfo]![FishID]

Now works great. Sorry for all the confusion. This is my first time using this site, and I am very impressed with the speed of the response. Even though you did not exactly figure out the problem, your assistance helped me figure out where I went wrong. If you want me to post the whole code for that button, just let me know.

Thanks again.
 
I am a visitor and Access beginner and have the same problem with access forms,please post the whole code for that button.
Thanks.
 
Here is the code for the button:

Private Sub butMorpho_Click()
On Error GoTo Err_butMorpho_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = &quot;frmMorpho&quot;

stLinkCriteria = &quot;[FishID]=&quot; & &quot;'&quot; & Me![FishID] & &quot;'&quot;
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
Forms![frmMorpho]![FishID] = Forms![frmCollectionInfo]![FishID]

Exit_butMorpho_Click:
Exit Sub

Err_butMorpho_Click:
MsgBox Err.Description
Resume Exit_butMorpho_Click

End Sub

Let me know this is confusing.
 
Hi,
Thank you very much,I will try this code and if I have any problems,I will mail again,
Regards,
Madu.
 
Hi Again,
I tried the code and it worked for one button,but I have several other buttons in the same form which need similar function.But I am getting a message box which says &quot;The Open form action was canceled&quot;,and for some it asks me to enter the parameter value and when i enter it it will give the same error.Any idea why this is happening?Has it got anything to do with the primary keys.The common column in all my tables is COMPID and I am trying this id to be in the forms which I enter using the buttons.Also I have made this as the primary key in all the tables.And this is for data entry forms.
Help me,
thanks,
Madu.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top