View Full Version : Using prelim info to open specific forms


MikeG
10-01-2001, 07:01 PM
I have a basic database with 3 linked tables with 3 forms/subforms. My switchboard has more options than I'd like: One button for adding new records, another to update existing entries. Instead of having both, can anyone recommend a way to request the primary key initially, then route the user to the ADD version of the input form if the key doesn't exist or an Update version if it does? I think I'm making more of this than I should. I've gone to the limit of my experience so if anyone can provide me with the cliff-note version of a layout, I'll go from there and hope for the best! Thanks in advance. I hope to someday be as good as most of you already are! Mike

charityg
10-02-2001, 11:12 AM
Say you have a textbox (txtkey) where the user would enter the primarykey. You would use the NoMatch property of the recordset to determine which form to open.

dim db as database
dim rst as recordset
set db=currentdb
set rst=db.openrecordset("TblName",dbopensnapshot)
rst.findfirst "primarykey=" & txtkey
'If primary key is a textvalue use:
rst.findfirst "primarykey='" & txtkey & "'"
if rst.nomatch=true then
docmd.openform "AddNew"
else
docmd.openform "Update"
endif

This is definitely the "cliffs notes" version, but it should get you started. If you have any trouble look up the noMatch property in Access help.


~Charity