Open Form at Specific Record ...but

MadeCurler

enthusiastic pensioner
Local time
Today, 22:50
Joined
Dec 6, 2007
Messages
49
I've been playing around with VBA and need some help. The procedure below works when I pass the value of "CboWhereTo" from a list box on a form via a Button's click event.

Public Sub WhereToNow(CboWhereTo)
If [CboWhereTo] = "Address & Domain" Then
DoCmd.OpenForm "FrmAddressDomain",acNormal
End If

I want the Form ("Address & Domain") to open at a specific record (say 125 of 600, and still show records from 125 to 600)and I've tried passing another argument to the sub (to tell it which record to open at) as below;

Public Sub WhereToNow(CboWhereTo as String,NewRecord as Integer) but when I call the procedure from the the Button's click procedure I get an error saying "expected expression or =".

I've tried all the usual places but I'm now turning to you as a last resort (as usual)...How do I pass two arguments to a procedure?? Thanks in advance.

Happy Christmas Bill Baird
 
Hi MadeCurler
I suspect that you have a way to identify all records from 125 only?
In which case, make a query that selects all records from 125 onwards and then base the form on the results of the query.

As for parsing 2 arguments, the procedure must be expecting them... so you would have
a function/procedure something like

function MyFunctionName(Arg1, Arg2)
'do stuff here
end function

Then - to parse the arguments you would say something like
MyFunctionName(ThisIsArg1, ThisIsArg2)
 
Suppose a form (frm_colr) is based on a table COLR (Colors) with the field colr_id as primary key. To open this form on a specific record, pass the primary key of that record to the OpenForm command in the OpenArgs argument:

Code:
DoCmd.OpenForm "frm_colr", , , , , , 3

The Onload event of frm_colr should be as follows:

Code:
Private Sub Form_Load()
    Recordset.FindFirst "colr_id = " & Int(OpenArgs)
End Sub
 
Code:
Sub GetCustomer(StrID As String)
Dim Rst As String
Dim Criteria As String
Dim GetRec As DAO.Recordset
DoCmd.OpenForm "PfrmCustomers"
Set GetRec = Forms("PfrmCustomers").RecordsetClone
            Criteria = "[CustomerID]='" & StrID & "'"
            GetRec.FindFirst Criteria
      If Not GetRec.NoMatch Then
        'Synchronize the form's record to the dynaset's record.
        Forms("PfrmCustomers").Bookmark = GetRec.Bookmark
      End If
      GetRec.Close
End Sub

Change "PfrmCustomers" To Your Form Name "
Criteria = "[CustomerID]='" & StrID & "'" Should be changed for your Forms ID Field and if the StrID is a long then '" & StrID & "'" should be changed to " & StrID
 
Hello!

I'm new to the community; actually, I just registered to say thanks to all the gentle help you give: Access might "seem clear and simple way of programming", but it is *not* :confused:

But well, my main intention is to thank you for the great help you've give about this issue. In special, to Dreamweaver as his solution totally helped me to solve the problem; I've been surfing the net for several hours until I found his suggestion and it worked amazingly.

By the way, I hope that if he ever comes by, he could explain why his solution works only if you keep the lines:


If Not GetRec.NoMatch Then
'Synchronize the form's record to the dynaset's record.
Forms("PfrmCustomers").Bookmark = GetRec.Bookmark
End If


I thought it was just a mere protection, but the search of the records does not work without them. Could you, or anyone, help me understand the concept behind this?

Thanks a lot.. you are great! :)
 
Last edited:

Users who are viewing this thread

Back
Top Bottom