Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Confirming a record exists on load event of a form

Posted on 2008-10-07
6
Medium Priority
?
292 Views
Last Modified: 2012-05-05
I know nothing about VBA.. but i use access regularly. (my VBA class is soon thank god)

here is my issue..

I have a report and a form that ask for "Lot_Number" when they are launched.

once the user enters that "Lot_Number" it launches the approite report or form.

If the user enters an incorrect lot number it still launches the form to the first "lot_number" record.

I want to return an error if the lot number is not in the system when they input it.


This is all i have so far..

Private Sub Form_Load()

Form.OnLoad

End Sub
0
Comment
Question by:Zerofun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 20

Expert Comment

by:clarkscott
ID: 22663084
In your first form... open the second form with
docmd.openform "yourform",,,,"Lot_Number = " & me.YourLotNumberField
 
in the Load event of the second form...
If isnull(me.YourLotNumber) then
       msgbox "no data"
       docmd.close
end if
 
Scott C
0
 

Author Comment

by:Zerofun
ID: 22663137
i need it to return the error even if they enter data... if the number they enter is not matched to a lot number in the database i need it to let them know and stop.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22663494
then, you have to check the existence of the record first before opening the form

how are you opening the form right now?
how is the data entered?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 38

Accepted Solution

by:
Jim P. earned 2000 total points
ID: 22663526
Try this:
Private Sub Form_Load()
Dim Lookup As String
Dim ValidLot As Boolean
 
Dim Msg As String
Dim Response As Integer
 
Lookup = ""
ValidLot = False
 
Do Until Lookup <> "" And ValidLot = True
    Lookup = InputBox("Please enter the lot number", "Lot Number", Lookup)
    
    If Lookup = "" Then
        MsgBox "Nothing entered. Please enter a valid lot number.", _
                vbOKOnly + vbCritical, "No Selection"
        ValidLot = False
    End If
    If Lookup <> "" Then
        If Lookup = DLookup("Lot_Number", "MyTable", "Lot_Number = '" & Trim(Lookup) & "'") Then
            Me.Filter = "Lot_Number = '" & Trim(Lookup) & "'"
            Me.FilterOn = True
            ValidLot = True
        Else
            Msg = "The lot number " & Lookup & " does not " & _
                "appear to be valid. " & _
                Chr(13) & _
                "Please enter a valid lot number " & Chr(13) & _
                "or cancel to exit."
                
            Response = MsgBox(Msg, vbCritical + vbOKCancel, "Invalid lot number")
            If Response = vbCancel Then
                ValidLot = False
                DoCmd.Close acForm, Me.NAME, acSaveYes
                Exit Sub
            End If
        End If
    End If
Loop
 
End Sub

Open in new window

0
 

Author Closing Comment

by:Zerofun
ID: 31503981
Thanks, you went above and beyond. this helped me a lot.
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 22664255
Glad to be of assistance. May all your days get brighter and brighter.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question