Problem with form not getting correct data in text box

G

Guest

I have two tables: tbltripheader (primary key is tripnumber) and tbltripdata
(primary is flttripnumber). Relationship is defined between the two on the
primary keys being equal.

On a form (control source is tbltripheader) the user begins the header
information for the trip. There is a command button that, when clicked,
opens another form where I want the user to enter the additional details
about the trip, which is to be stored in tbltripdata.

I'm having a problem getting the tripnumber from the first form to
automatically load/display on the second form as the flttripnumber. When I
try setting the control source of the textbox on the second form for
flttripnumber=Forms!frmtripheader.tripnumber I get the value but the database
still thinks it's Null.

In addition, I'm trying to make sure that only one record can be added on
the second form for each tripnumber.

Any ideas?
 
A

Allan Murphy

You are setting the value of the flttripnumber field to the value on the
first form, but it is not stored on the second form as flttripnumber.

form1 is the form used to open the second form

In your second form using the ON LOAD event add

me!flttripnumber = Forms!form1!tripnumber

I suggest you set the property of the field that holds the flttripnumber to
locked or make invisible so that the user can not change the value.
 
G

Guest

Here's the code I use to open a reciever form from a PO form.
Private Sub Command65_Click()
On Error GoTo Err_Command65_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Purchase Orders Receiver"

stLinkCriteria = "[PurchaseOrderID]=" & Me![PurchaseOrderID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command65_Click:
Exit Sub

Err_Command65_Click:
MsgBox "You must have an active PO open to open the Recievers Form",
vbOKOnly

Resume Exit_Command65_Click

End Sub
 
G

Guest

A couple of things happening now:

1. Forms does open with value of form2.tripnumber being equal to
form1.tripnumber and displaying in the textbox correctly. But, if you close
form2 and then open it again from the form1.buttonclick, the values entered
previously are not there---the trip number is, but not the other data.

2. I've also noticed that after you enter the data on form2, after tabing
out of the last textbox, it starts a new record. I don't want this to occur.
There should only be one record per tripnumber. (The way it is now, since
tripnumber is a primary key, you get an error anyway. But, is there a way to
prevent this from occuring all together?)

BTW, I also integrated the example sub given in the other user's reply to my
original post. Same things occur.)

Many thanks for your assistance.
 
A

Allan Murphy

If there is only one record for each trip, why do you need two tables?


Allan Murphy
mail: (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top