Access handling

B

blaze

I would like to set up a window that would be called from my switch board
where I would enter a number. have the number checked against a database and
if it is in the data base be placed on that record or otherwise asked if I
would like to add a new record to the DB.

Could anyone tell me how to do this using simple sentences?
 
S

Steve Schapel

Blaze,

There are a number of ways of going about this. And I am not 100% clear
what "be placed on that record" means, but I assume this is a record ID
numberr of some sort. So, I'll have a go. Let's use an Input Box to
get the number from the user. So, on the Click event of the button on
your switchboard form, you could put a VBA procedure something like this...

' create a variable for the number
Dim KeyNumber As Long
' open an input box for the entry of the required number
KeyNumber = InputBox("What is the number?")
' see if there is already a record in the table with this number
If DCount("*","YourTable","[YourID]=" & KeyNumber) > 0 Then
' if so, open the form at that record
DoCmd.OpenForm "YourDataForm", , , "[YourID]=" & KeyNumber
Else
' if not, ask with a message box about adding a new record
If MsgBox("Add new?", vbQuestion + vbYesNo) = vbYes Then
' if so, open the form at a new record
DoCmd.OpenForm "YourDataForm", , , , acFormAdd
' ... and insert the number into the new record
Forms!YourDataForm!YourID = KeyNumber
End If
End If

Hope that makes sense. You will, of course, need to replace the actual
names of your own form and table and field into the above example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top