Adding a record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I am trying to add/update a table (tblTravel) I have a form (frmTravel)
previous to this form there is another form(frmMeeting) were the user clicks
on a button. What I want that button to do is check if record exist. There
is frmMeeting.field1 and frmMeeting.field2. If field1 = tblTravel.field1 and
field2 = tblTravel.field2 then I want to update and bring up frmTravel with
all the fields in that record. Else I want frmTravel to add a new record.
Pease Help and Thank you.
 
Try something like the following from the button on frmMeeting:

DoCmd.OpenForm "frmTravel",,,"[Field1]='" & Me.[Field1] & "' AND [Field2]='"
& Me.[Field2] & "'"

Beware of unintended line breaks - the command should all be one line.
 
That is simular to what I am currently doing, but that only puts the
frmMeeting.field1 and frmMeeting.field2 up on the form (frmTravel). It does
not check to see if it is already within the table (tblTravel). If they
match then update otherwise (else) add new record.
Unless I am missing something.

kingston via AccessMonster.com said:
Try something like the following from the button on frmMeeting:

DoCmd.OpenForm "frmTravel",,,"[Field1]='" & Me.[Field1] & "' AND [Field2]='"
& Me.[Field2] & "'"

Beware of unintended line breaks - the command should all be one line.
Hi,
I am trying to add/update a table (tblTravel) I have a form (frmTravel)
previous to this form there is another form(frmMeeting) were the user clicks
on a button. What I want that button to do is check if record exist. There
is frmMeeting.field1 and frmMeeting.field2. If field1 = tblTravel.field1 and
field2 = tblTravel.field2 then I want to update and bring up frmTravel with
all the fields in that record. Else I want frmTravel to add a new record.
Pease Help and Thank you.
 
Is frmTravel not directly bound to tblTravel? If it is, the OpenForm command
will open the form and find record(s) that match the criteria (it doesn't put
the field values into frmTravel). If there is no match, it will open to a
new record. If you need to check for the existence of a record in tblTravel,
one way to do it is to use the DCount() function:

If DCount("*","tblTravel","Field1='"& Value1 & "' AND Field2='" & Value2 &
"'")= 0 Then...
That is simular to what I am currently doing, but that only puts the
frmMeeting.field1 and frmMeeting.field2 up on the form (frmTravel). It does
not check to see if it is already within the table (tblTravel). If they
match then update otherwise (else) add new record.
Unless I am missing something.
Try something like the following from the button on frmMeeting:
[quoted text clipped - 11 lines]
 
Back
Top