Full Version: Help With If Statement To Open Form And Go To Record
UtterAccess Forums > Microsoft® Access > Access Forms
CalebFDA
Hi
I have a continuous form where for each record on the form i have a button that says "Edit/View". The record source for this continuous form is a query that draws records from a table but has associated tables where some of the information is entered. In this example, it lists the obligations for both Contracts and Grants, but the actual background info on a contract or grant is stored in different tables and is entered via different forms. I would like the user to be able to go to the record in either the contract form or the grant form depending on what record they click on. I have been playing with an if then statement to do this. The problem is that when it executes it starts to tell me that i need to enter parameter values. I am not sure why the main contract or grant form is not recognizing the record and updating the subforms. . I believe it is flagging because of what is in the on open command in the contract or grant forms....which are merely requeries for lists and such. Here is the on open code for the grants form. The first flag i get is on the listtraining.requery
DoCmd.GoToRecord , , acNewRec
'requery lists
Forms!frm_grant.subfrm_grantyear.Form!ListYear.Requery
Forms!frm_grant.subfrm_training.Form!ListTraining.Requery
Forms!frm_grant.subfrm_notes.Form!ListNotes.Requery
Forms!frm_grant!OAGPosition.Requery
Forms!frm_grant!OAGOffice.Requery
Forms!frm_grant!OAGPhone.Requery
Forms!frm_grant!OAGFax.Requery
Forms!frm_grant!OAGEmail.Requery
Forms!frm_grant!OAGID.Requery
'enable/disable main form fields
Me.Combo37.SetFocus
Me.GrantNumber.Enabled = False
Me.GrantStart.Enabled = False
Me.GrantEnd.Enabled = False
Me.StateID.Enabled = False
Me.ProgramID.Enabled = False
Me.Save.Enabled = False
Me.New.Enabled = True
Me.Get.Enabled = True
Me.OAGID.Enabled = False
Me.OAG_Save.Enabled = False
THere is the code for my button on the continuous form.
If [contractid]="0" Then
Docmd.openform "frm_grant", acNormal,,"[grantid]=" & Me!GrantID
Else
Docmd.openform "frm_contract", acNormal,,"[contractid]=" & Me!ContractID
End If
jzwp11
What is the data type for contractID and grantID
You have this
If [contractid]="0" Then
Docmd.openform "frm_grant", acNormal,,"[grantid]=" & Me!GrantID
Else
Docmd.openform "frm_contract", acNormal,,"[contractid]=" & Me!ContractID
End If
In the IF..THEN you have the zero in quotes which implies a text field but in the docmd for the frm_contract you have the contractID as numeric.
CalebFDA
Datatype for the IDs is a number. Let me try changing that. Thanks.
jzwp11
Let us know how it works out
CalebFDA
everything seems to be working fine now. thanks
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.