Need help with code on Search form, please??

G

Guest

I am fairly new to coding, so please bare with me. I have been working on
this code for weeks to get it to the point of where it is. I have a form
called (Find Employee) set up that is only used to find records from a table
(BadgeData) and returns the record on another form (IndivData). On the Find
Employee form, there are three text boxes that are unbound but exist in the
BadgeData table(Badge Number, FName, & LName). I created a command button
(btnFindBadgeData) to use the data entered on the Find Employee form, search
the BadgeData table and return the record on the IndivData form. The problem
is...no records are being returned. I get the message box saying no records
found even though the data I'm using to test the form came directly from the
record source table!!

I am a bit new at coding, so I can't figure out why this is happening. I
searched other threads and can't seem to find any that would help me. If
anyone can help me figure out what's wrong here or point me to a thread that
will help, I'd greatly appreciate it!

Code:
Private Sub btnFindBadgeData_Click()On Error GoTo Err_btnFindBadgeData_Click
Dim stDocName As String Dim stLinkCriteria As String stDocName =
"IndivData" If (stLinkCriteria = "[CardNum]=" & "'" & Me![CardNum] & "'" _
& "OR [FName]=" & "'" & Me![FName] & "'" _ & "OR [LName]=" &
"'" & Me![LName] & "'") Then DoCmd.OpenForm stDocName, , ,
stLinkCriteria Else Beep MsgBox "No employee data was
found." _ & vbCrLf & vbCrLf _ & "Please try again.",
vbInformation CardNum.SetFocus End If Me.[CardNum] = Null
Me.[LName] = Null Me.[FName] = NullExit_btnFindBadgeData_Click:
Exit SubErr_btnFindBadgeData_Click: MsgBox Err.Description Resume
Exit_btnFindBadgeData_Click End Sub
 
M

Marshall Barton

Tiffany said:
I am fairly new to coding, so please bare with me. I have been working on
this code for weeks to get it to the point of where it is. I have a form
called (Find Employee) set up that is only used to find records from a table
(BadgeData) and returns the record on another form (IndivData). On the Find
Employee form, there are three text boxes that are unbound but exist in the
BadgeData table(Badge Number, FName, & LName). I created a command button
(btnFindBadgeData) to use the data entered on the Find Employee form, search
the BadgeData table and return the record on the IndivData form. The problem
is...no records are being returned. I get the message box saying no records
found even though the data I'm using to test the form came directly from the
record source table!!

I am a bit new at coding, so I can't figure out why this is happening. I
searched other threads and can't seem to find any that would help me. If
anyone can help me figure out what's wrong here or point me to a thread that
will help, I'd greatly appreciate it!

Code:
Private Sub btnFindBadgeData_Click()
On Error GoTo Err_btnFindBadgeData_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "IndivData"
If (stLinkCriteria = "[CardNum]=" & "'" & Me![CardNum] &
"'" _
& "OR [FName]=" & "'" & Me![FName] & "'" _ & "OR
[LName]=" & "'" & Me![LName] & "'") Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
Beep
MsgBox "No employee data was found." _
& vbCrLf & vbCrLf _
& "Please try again.", vbInformation
CardNum.SetFocus
End If
Me.[CardNum] = Null
Me.[LName] = Null
Me.[FName] = Null
Exit_btnFindBadgeData_Click:
Exit Sub
Err_btnFindBadgeData_Click:
MsgBox Err.Description
Resume Exit_btnFindBadgeData_Click
End Sub


The code you posted lost all the newlines so it's really
difficult to decipher. If the code above has the newlines
properly restored, then I don't see what the If statement
has to do with anything. You haven't set stLinkCriteria to
a value, so checking if it has a specific value in kind of
meaningless. At the very least it's guaranteed to never
open the other form. Get rid of the If and just assign the
the filter string to stLinkCriteria

I suggest that you forget about checking if any data was
found for now and just get the other form to open. (This is
not the right place to check for no data anyway)

Post back with whatever results you get and see what you can
do about making the code post properly.
 

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