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!

Access VBA/Forms how to open in add mode.

Status
Not open for further replies.

Shakes83

Programmer
Jun 23, 2006
11
CA
Hello,

I have a form (frmMain) with two sub forms (SubA and subB). When frmMain loads the textboxes within SubA are populated from a query that returns values from a local table based on whether a certain ID exists in the table. My problem is that if the ID does not exist the query returns no records and consequently the sub form (SubA) is greyed out and is not enabled, or so it seems. However, if the query and in turn SubA returns no records, I'd like the end user to be able to add a new record through form SubA. I've tried writing code for a button so that the button can allow the user to GoTo new record but it did'nt work. My question is:

How can I design SubA either in its onload event or in the onload event of frmMain so that when the query returns no IDs the user is taken to a new blank record so he/she can enter a new ID ?

Cheers,
Al
 
yes if you pop up a form for data entry when you close the form you need to requery, which unfortunately takes you back to the first record. So you need to save your bookmark. your main form to see the additions.

In your case.

Private Sub New_Record_Click()
Dim bk As Variant
bk = Me.Bookmark
Me.Requery

If Form_ER_DonrContact.RecordsetClone.RecordCount = 0 Then
DoCmd.OpenForm Form_ER_DonrContact, acNormal, , , acFormAdd, acDialog
me.requery
me.bookmark = bk
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top