Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use formname as variable in findfirst

Status
Not open for further replies.

fedum

Technical User
Mar 22, 2004
104
BE
Hi,
I would like to use my code form more then one form to find a record on the form. I have tried to change the code but get error or no result. What is wrong?
The problem is in the
SET RS.....

...BOOKMARK


Code
Private Sub btnZoeken_Click()

On Error GoTo Err_btnZoeken_Click

' De record zoeken die overeenkomt met het besturingselement
Dim rs As Object
Dim ZoekNummer As String
Dim Bontype As String
Dim Formuliernaam As Form


If IsLoaded("frmOpvolging") Then
Set Formuliernaam = Forms!frmOpvolging
End If

If IsLoaded("frmOverzichtdocumenten") Then
Set Formuliernaam = Forms!frmOverzichtdocumenten
End If

ZoekNummer = txtBonnr
Bontype = cboTypeBon


'HERE IS THE PROBLEM I THINK!!!
Set rs = Forms!frmOpvolging.RecordsetClone
'Set rs = Formuliernaam.RecordsetClone
Select Case Bontype

Case "factuur":
rs.FindFirst "[faktuurnr] = " & ZoekNummer
If rs.NoMatch Then
MsgBox "Bonnummer niet gevonden"
Else
DoCmd.Close
Forms!frmOpvolging.Bookmark = rs.Bookmark
'Formuliernaam.bookmark=rs.bookmark
End If
End Select


Exit_btnZoeken_Click:
Exit Sub

Err_btnZoeken_Click:
MsgBox Err.Description
Resume Exit_btnZoeken_Click



End Sub
 
Try
Private Sub btnZoeken_Click()

On Error GoTo Err_btnZoeken_Click

' De record zoeken die overeenkomt met het besturingselement
'be specific in your recordset dimension
Dim rs As dao.recordset
Dim ZoekNummer As String
Dim Bontype As String
Dim Formuliernaam As access.Form


If IsLoaded("frmOpvolging") Then
Set Formuliernaam = Forms!frmOpvolging
elseif IsLoaded("frmOverzichtdocumenten") Then
Set Formuliernaam = Forms!frmOverzichtdocumenten
End If

ZoekNummer = txtBonnr
Bontype = cboTypeBon
'HERE IS THE PROBLEM I THINK!!!
'it is easier to use the recordset then deal with bookmarks
Set rs = Formuliernaam.Recordset
Select Case Bontype
Case "factuur":
rs.FindFirst "faktuurnr = " & ZoekNummer
'if text rs.FindFirst "faktuurnr = '" & ZoekNummer &"'"
If rs.NoMatch Then
MsgBox "Bonnummer niet gevonden"
Else
'always specify what you are closing
DoCmd.Close acform,frm.name
End If
End Select
Exit_btnZoeken_Click:
Exit Sub

Err_btnZoeken_Click:
MsgBox Err.Description
Resume Exit_btnZoeken_Click
End Sub
 
Thanks!
You made me smile again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top