SetFocus on continuous form (1 Viewer)

ejstefl

Registered User.
Local time
Today, 01:00
Joined
Jan 28, 2002
Messages
378
Hello,

I have a continuous form. On that form, I have a link (label) that a user can click to bring up a new form containing more info on the current record. The problem is that when the form opens, the first record is selected. If the user scrolls down to another record, and clicks the link, the form opens with info on the first record.

It seems that I need to set the record to the record that the link was clicked from, but I'm not sure how. Any help?

Thanks,
Eric
 
R

Rich

Guest
Use the Where clause of the OpenForm method, you should be able to find examples here
 

ejstefl

Registered User.
Local time
Today, 01:00
Joined
Jan 28, 2002
Messages
378
That doesn't really work - I have no way of knowing which record the user clicked on, since the active record remains the first record on the list. I need a way to make the record the user clicked the link from be the active recrd.
 
R

Rich

Guest
Why does the first record remain the active record if they use the arrow keys to navigate?
 

ejstefl

Registered User.
Local time
Today, 01:00
Joined
Jan 28, 2002
Messages
378
Not by using the arrow keys - but by using the mouse. You can see maye 3 or 4 records at once, since it is a continuous form. If you click on the third record's link, it will open the new form, but display the first record's info. See the attached image... If I were to click on the "Instructions" link for Bermuda, I'd see instructions for Belgium, since it is the active record.
 

Attachments

  • Form.jpg
    Form.jpg
    53.9 KB · Views: 152

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:00
Joined
Feb 19, 2002
Messages
43,396
You'll need to modify the code in the click event of the link. Add a "where" argument to the OpenForm method so that the correct record is selected.
 

ejstefl

Registered User.
Local time
Today, 01:00
Joined
Jan 28, 2002
Messages
378
That works, but it sort of goes against the look and feel of the rest of the database. Any idea on how to make it work using a label?
 

ejstefl

Registered User.
Local time
Today, 01:00
Joined
Jan 28, 2002
Messages
378
Pat Hartman said:
You'll need to modify the code in the click event of the link. Add a "where" argument to the OpenForm method so that the correct record is selected.

This is the code:
Code:
    Dim strInstructions As String
    
    strInstructions = "BNY A/C " & Me.txtBnyAccount & vbCrLf & vbCrLf & _
                      Me.CountryName & vbCrLf & vbCrLf & _
                      "Security Instructions:" & vbCrLf & vbCrLf & _
                      Me.txtSubCustodianBankName & vbCrLf & _
                      Me.txtBIC & vbCrLf & _
                      "Securities Account " & Me.txtSecuritiesAccount & vbCrLf & _
                      "Reference BNY A/C " & Me.txtBnyAccount & " " & Me.txtBNYAccountNAme & vbCrLf & vbCrLf & _
                      "Cash Instructions:" & vbCrLf & vbCrLf & _
                      Me.txtSubCustodianBankName & vbCrLf & _
                      Me.txtBIC & vbCrLf & _
                      "Cash Account " & Me.txtCashAccount & vbCrLf & _
                      "Reference BNY A/C " & Me.txtBnyAccount & " " & Me.txtBNYAccountNAme & vbCrLf & vbCrLf & _
                      "Additional Info: " & Me.AdditionalInfo & vbCrLf & vbCrLf & _
                      "Notes: " & Me.Notes

    DoCmd.OpenForm "frmInstructions"
    Forms!frmInstructions.txtInstructions = strInstructions

I'm not sure where to put the where clause, as i have no way of knowing which link the user clicked on...
 
R

Rich

Guest
I'm almost certain that since a label by definition can't receive the focus Access doesn't move the pointer to the current record
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:00
Joined
Feb 19, 2002
Messages
43,396
Are you guessing at syntax for the OpenForm method or did you look it up?

DoCmd.OpenForm "frmInstructions", , , "BankID = " & Me.txtBankID

Change "BankID" to whatever the unique id of the record is.
 

ejstefl

Registered User.
Local time
Today, 01:00
Joined
Jan 28, 2002
Messages
378
Pat Hartman said:
Are you guessing at syntax for the OpenForm method or did you look it up?

DoCmd.OpenForm "frmInstructions", , , "BankID = " & Me.txtBankID

Change "BankID" to whatever the unique id of the record is.

No, I'm not guessing at the syntax. I just have no options. I open an unbound form, and set an unbound textbox on that form to the string I build in the code. Its an easy way to display the information so it can be copied and pasted.

However, if it were a bound form, and I used your code, it would still open to the first record, since when I click the link in any record, "me" still refers to the first record.

I feel like I'm not explaining myself very well. Look at the picture - Belgium is the currently selected record, right? Now, if I click on "Instructions" under Bangladesh, the currently selected record remains Belgium. So, the "Me.txtBankID" in your code would still refer to Belgium, even though I clicked on the link under Bangladesh.

If I change it to a text box or command button as Rich suggests, the code works perfectly. Apparantly, clicking on a text box or button first sets the focus to the country i clicked on first, then executes the code. Is there any way to simulate this with a label, so I can retain the look of a link?
 

le888

Registered User.
Local time
Yesterday, 21:00
Joined
Dec 10, 2003
Messages
344
Here is an option, leave the label. Create a button and put on top of the label. Then goto the propriety of the button and put it on transparent. It is important that your button control is on top of your label otherwise, this would not work. Try it.

Le
 

ejstefl

Registered User.
Local time
Today, 01:00
Joined
Jan 28, 2002
Messages
378
le888 said:
Here is an option, leave the label. Create a button and put on top of the label. Then goto the propriety of the button and put it on transparent. It is important that your button control is on top of your label otherwise, this would not work. Try it.

Le

That did the trick!!! Thank you so much! I forgot you could make buttons transparent!
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:00
Joined
Feb 19, 2002
Messages
43,396
Belgium is the currently selected record, right? Now, if I click on "Instructions" under Bangladesh, the currently selected record remains Belgium. So, the "Me.txtBankID" in your code would still refer to Belgium, even though I clicked on the link under Bangladesh.
When you click on the link under Bangladesh, that becomes the current record.
 

ejstefl

Registered User.
Local time
Today, 01:00
Joined
Jan 28, 2002
Messages
378
Pat Hartman said:
When you click on the link under Bangladesh, that becomes the current record.

Ah, you'd think so! But that's what I was tyring to say - for some reason, Bangladesh was NOT becoming the currently selected record. The label I was using had a "space" in the hyperlink property, to cause the hand icon to appear. I think that was the problem, as when you clicked the label, it did not select the record.

To fix it, I created a button, set the transparent property to yes, and associated the label to the button. I made the button and its associated label the same size, and moved them on top of each other. I then put the code behind the button instead of the label. This worked!
 

Users who are viewing this thread

Top Bottom