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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gotorecord problem

Status
Not open for further replies.

medic133

Technical User
Apr 7, 2002
86
US
I have a textbox called patientid and a command button on form1. In the onclick command of the command button I open form2 which also ahas a textbox called patientid. Prior to opening form2 a query is run on the table of which form2 is based to see if there is a record equal to the value of patientid on form1. The query runs great. I then have an if..then statement which causes form2 to open to a new record if the query result is null or to the recor equal to the patientid of form1. How do I get form2 to open to this query result if it isn't null? I tried acgoto, "Queryname" in the gotorecord line without success.

Thanks in advance.
 
Hi, you can do it like this...

If form2 is bound to a recordset, in the onclick event of the button

DoCmd.OpenForm "Form2", acNormal, , "PatientID = " & PatientID

This basically says, open form2 in Normal view and goto the record where PatientID = PatientID on form1



There are two ways to write error-free programs; only the third one works.
 
GHolden,

Thanks! Works like a charm! I was hoping this would be a simple fix, but I was afraid I was going to have to get into identifying recordsets or something. I totally forgot about the where part of the openform statement. Thanks again!
 
GHolden,

OK. I spoke too soon. I'm able to populate the textboxes with the information in the where clause of the openform statement, but it doesn't fill in the rest of the record.

Here's a little description of what I've got.

Form1 has a command button that opens form2. Before the form is opened, I run a query to see if there are any records for form2 that match two fields on form1. If not, form2 opens to a new record. If there is a record match, I want form2 to open to that record. Here's what I have for the code for form1 to open form2:

docmd.openform "form2name",acNormal, , "ShiftID=[forms]![form1name]![ShiftID] AND PatientID=[forms]![form1name]![PatientID]

I've checked this against existing records, but form2 opens to the values specified, but the rest of the form looks like a new record. Please HELP!
 
Hi,

Are all the controls on the form that you are opening bound to the recordset for the form?



There are two ways to write error-free programs; only the third one works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top