|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Error Message
Hi everyone. Listen I creating a database in Access and I have developed a search engine in a form where the user types in a record number and then clicks on the search button which sends them to the correct record. However a problem that I'm currently having is when the user types in a wrong / non-existent record number the system sends the the user to blank form. I don't want it to do this, I would like it display an error message to the user. I'm trying to get the system to do this by running macro through the VBA. My code looks like this:
Dim stDocName As String Dim stLinkCriteria As String stDocName = "ADMIN NUMBER calculate table Query" stLinkCriteria = "[Admin Number]=" & "'" & Me![Find Admin Num] & "'" DoCmd.OpenForm stDocName, , , stLinkCriteria **If stLinkCriteria = "[Admin Number]<>" & "'" & Me![Find Admin Num] & "'" Then Dim errormsg As String errormsg = mcrConvertYourMacros_MSG2 End If** 'End Function Exit_Command71_Button_Click: Exit Sub Err_Command71_Button_Click: 'If stLinkCriteria = "[Admin Number]<>" & "'" & Me![Find Admin Num] & "'" Then 'DoCmd.RunMacro(MSG2, [0], [0]) = stLinkCriteria 'End If MsgBox Err.Description Resume Exit_Command71_Button_Click I have set off the part where I trying to get error message to come up in astrisks to help you view the code more clearly. Could someone please help me? Thanks, Spicoli |
|
#2
|
||||
|
||||
|
Hi,
I'm not sure what your Table/Field are called so you will have to amend the SQL statement accordingly, but try something like this to perform a select query first and if it retrieves a record then do your command, if not, display a message: Code:
Dim stDocName As String
Dim stLinkCriteria As String
Dim db As Database
Dim strUserInput As String
strUserInput = InputBox("Please Enter an Admin Number")
Set db = CurrentDb
Dim rs As DAO.Recordset
Set rs = db.OpenRecordset("select * from YourTable where AdminNumber = '" & strUserInput & "'")
If ((rs.EOF = True) And (rs.BOF = True)) Then
MsgBox ("No Record Found")
Else
stDocName = "ADMIN NUMBER calculate table Query"
stLinkCriteria = "[Admin Number]=" & "'" & Me![Find Admin Num] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
rs.Close
End Sub
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Error Message |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|