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

How to open FORM either in AddNew State or Edit !

Status
Not open for further replies.

bn2335813

Programmer
Oct 8, 2001
10
IL
I have a Form/SubForm basicly based on a 'Tbl1'.
I would like to check and see if a spesified record exists (based on ID) and to Open the Form eithr on the AddNew record '*' mode or Edit mode for the allready existing record .

Thanks!
 
Hi!

I am assuming that you will do this in code probably with the click of a button. If so, use this code:

Dim sql As String
Dim rst As DAO.Recordset

sql = "Select ID From Tbl1 Where ID = '" & txtID & "'"
Set rst = CurrentDb.OpenRecordset(sql, dbOpenDynaset)

If rst.EOF = True And rst.BOF = True Then
DoCmd.OpenForm "YourForm", , , , acFormAdd
Else
sql = "ID = '" & txtID & "'"
DoCmd.OpenForm "YourForm", , , , , sql
End If

The code above assumes that your ID field is text, if it is numeric then leave out the single quotes.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top