Access 2003 - Get Current Record in VBA

horton_brian

New member
Local time
Today, 10:07
Joined
May 4, 2010
Messages
9
I'm developing a small Access 2003 app for a local charity and it's going well using wizard-created screens, but I'm stuck on a couple of issues:
1. One of the fields needs to be automatically populated with the creation date of the record. How do I get to that?
2. I'd like a control to be visible or not depending on the value in one of the fields in the currently displayed record; how do I access from VBA the fields of the current record?
3. I'm using a tab control but in Form View the screen opens up scrolled down slightly so the tabs are not visible; resizing the screen in design view makes no difference to this.
Any help would be appreciated!
Brian
 
Probably nobody has answer because of the third. The others are fairly simple:

1) The simplest is to give the field in the table a default value of Date()

2) In code behind the form, "Me" refers to that form, so Me.ControlName refers to the control containing the value you want to test. From the sound of it, you'd want code in the current event to handle the changing of records and the after update event of the control containing the value to be tested, to handle it being changed.

3) My only thought is that the first control with focus is far enough down the screen to force the screen to scroll a bit. Maybe you can post a picture?
 
Thanks for that Paul:
1) Good idea, thanks - seems to work
2) Thanks, I know how to get the current values from a control, but what event would I use to change the Visible property of the control I want to appear conditionally as I step from record to record? I can't find any events for the Navigation Toolbar control. I see from Help you can build your own Navigation Toolbar control out of custom controls and assign record navigation to it then it will presumably have events you can use, but it seems a lot of trouble!
3) See attached screenshot - as you can see the first field is near the top.
Brian
 

Attachments

  • Tab Scrolled Screenshot.jpg
    Tab Scrolled Screenshot.jpg
    93.7 KB · Views: 341
2) You must have missed this:

you'd want code in the current event to handle the changing of records

My only suggestion on 3 might be to have the first control with focus to be at the top. If that doesn't work, it might help to have a sample of the db to play with. I've never had this problem, but I always design forms so they fit completely on the screen.
 
Problem # 3 is always caused by, as Paul suggested, the first control on the tabbed page being low enough on the page to require scrolling to show it.

The definitive answer is to do as Paul and most experienced developers do and not design a form/tabbed pages that are too long to fit on the screen.

As a workaround, you need to go into Design View, select the page in question, the goto View - Tab Order and set the Tab order for your page so that the first control on the page to get focus is at the top of the page.

Alternatively, you could handle it in code
Code:
Private Sub TabControlName_Change()
 
 Select Case TabControlName

  Case 0 'First Page
    Page1TextBox.SetFocus
    
  Case 1 'Second Page
    Page2TextBox.SetFocus
   
  Case 2 'Third Page
    Page3TextBox.SetFocus
    
  End Select

End Sub

where Page1TextBox, Page2TextBox, etc is a control on the given page near the top.
 
The other thing you can do is resize your subform/tabs so that you don't need to scroll.
 
3) Sorted! Although all my data controls fitted into the basic window, the tab control itself was too big.
Brian
 
I've now found the event for 2) - the form's 'On Current' event. Thanks for the help.
Brian
 

Users who are viewing this thread

Back
Top Bottom