find a record

Thedon123

Registered User.
Local time
Today, 18:28
Joined
Sep 11, 2002
Messages
98
I have a button that opens a form a form where i add data. This form "ADD NAMES" is dependant on there being a user selected alraedy in another table.

When there are no users in this table it opens the form anyway and causes it to crash.

So the question is how do i get the the button when clicked to first search to see if a user is presnent then.

1. if there is no user open another form to add a user
or 2. to open the add name form.

p.s. the button uses a module which has the command to open the form.
 
I hope you're using event handling so end users dont get the vb window where they can easily modify your code and save it.

Otherwise all you got to do is check if a record exists...if not open another form.

For instance:

Code:
On Error Goto Hell

Dim db as Database
Dim rs as Recordset
Dim strSQL As String

strSQL = "SELECT * FROM tblYourTable WHERE UserName='" & SomeNameVariable & "'"

Set db = currentdb
set rs=db.openrecordset(strSQL)

if rs.bof then
  'no records open a form to add a user
  DoCmd.OpenForm "SomeForm"
else
  'user exists open another form
  DoCmd.OpenForm "otherform"
end if

Heaven:
Set rs= nothing
set db = nothing
exit sub

Hell:
MsgBox Err.Description
Resume Heaven

Jon
 
Thank you very much
 

Users who are viewing this thread

Back
Top Bottom