473,394 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Setfocus on subform

67 64KB
Hi,

In my access application, there are four main forms and each form has tab control with other two sub forms.

There is data transmission between access and other database, which subform will call batch file to run to update data on access table. During running batch file, user can click on any form. After batch file finish running, I have place me.requery.

Could anybody tell me what is me refer to? is it refer to the form in vba code or the form the get focus? I have this problem because after calling me.requery from that sub form, the new data didn't show up, I have to set focus on other form then go back to it again, then it will shows new data.

Best regards,
Sophanna
May 31 '14 #1
8 3118
NeoPa
32,556 Expert Mod 16PB
Me always refers to the object (which can be a form or a report.) associated with the module the reference is in.

IE. If your main form is called frmMain and you have an associated module with that (Form_frmMain) then any reference within that module will refer to that specific form.
Jun 1 '14 #2
sophannaly
67 64KB
Hi Neo,

Would you mind to explain in an easy way cuz i'm not really understand this? On my subform, I have button which will call module code to run. Does this module is what you mean?

Best regards,
Sophanna
Jun 2 '14 #3
NeoPa
32,556 Expert Mod 16PB
I think so. It's hard for me to understand you too.

Event procedures (EG. Control_AfterUpdate() or Button_Click()) are always created for you automatically in the object's associated module.
Jun 2 '14 #4
sophannaly
67 64KB
Hi Neo,

I'm really sorry for that. I have this problem cuz in my form, on click button event, I have code which will call batch file to run, and this batch file will erase all data from existing ms access table, then import data from Postgresql DB to this access table. And i'm sure that after this batch file finish running, it means that data is already wrote to access table.
Expand|Select|Wrap|Line Numbers
  1.         runBAT ("Download_LastYear_Request_Expenditure\Download_LastYear_Request_Expenditure_run.bat")
  2.         .Caption = lblDownloadLastYearBudget()
  3.         .Enabled = True
  4.     End With
  5.  
  6.     Me.Requery
But it just so strange, for me.requery it will shows as #Deleted for all record in continuous form. I have to go to other form then come back to this form again, then it will show data again.

So I think about solution as first set focus to other form (its mainform), then set focus back to this form(subform). But there is nothing change.

And when I use msgbox me.name, it shows this subform's name correctly.

So I think that during this VBA code run, we can use mouse to click on any other form, but for VBA code, it still remaining running on the form that we have call it to run.

The above is the reason why I came up with this question.

Best regards,
Sophanna
Jun 4 '14 #5
NeoPa
32,556 Expert Mod 16PB
Sophanna:
"But it just so strange, for me.requery it will shows as #Deleted for all record in continuous form."

I think that's not quite right. I would expect that if you were using Me.Refresh. You should never see #Deleted after a Me.Requery. Please check this before we proceed.
Jun 4 '14 #6
sophannaly
67 64KB
Hi NeoPa,

Please a look at my screen shot.This my continuous form.
Below is the code that I use to call on button to run batch file
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnFillWithNewRevision_Click()
  2.     On Error GoTo err_handler
  3.     If Me.Dirty Then
  4.         Me.Dirty = False
  5.     End If
  6.  
  7.     With Me.btnFillWithNewRevision
  8.         .Caption = lblPleaseWait()
  9.         .Enabled = False
  10.         runBAT ("Download_LastYear_Request_Expenditure\Download_LastYear_Request_Expenditure_run.bat")
  11.         .Caption = lblDownloadLastYearBudget()
  12.         .Enabled = True
  13.     End With
  14.  
  15.     'Sleep (5000)
  16.     Me.Requery
  17.  
  18. err_handler:
  19.     Exit Sub
  20. End Sub
Before I use code that you provide on calling batch file and wait, but it doesn't help, so I tried with code that I got from Microsoft website, but it also doesn't help.
Below is the module code that I use to call batch file
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Type STARTUPINFO
  4.    cb As Long
  5.    lpReserved As String
  6.    lpDesktop As String
  7.    lpTitle As String
  8.    dwX As Long
  9.    dwY As Long
  10.    dwXSize As Long
  11.    dwYSize As Long
  12.    dwXCountChars As Long
  13.    dwYCountChars As Long
  14.    dwFillAttribute As Long
  15.    dwFlags As Long
  16.    wShowWindow As Integer
  17.    cbReserved2 As Integer
  18.    lpReserved2 As Long
  19.    hStdInput As Long
  20.    hStdOutput As Long
  21.    hStdError As Long
  22. End Type
  23.  
  24. Private Type PROCESS_INFORMATION
  25.    hProcess As Long
  26.    hThread As Long
  27.    dwProcessID As Long
  28.    dwThreadID As Long
  29. End Type
  30.  
  31. Private Declare PtrSafe Function WaitForSingleObject Lib "kernel32" (ByVal _
  32.    hHandle As Long, ByVal dwMilliseconds As Long) As Long
  33.  
  34. Private Declare PtrSafe Function CreateProcessA Lib "kernel32" (ByVal _
  35.    lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
  36.    lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
  37.    ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
  38.    ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
  39.    lpStartupInfo As STARTUPINFO, lpProcessInformation As _
  40.    PROCESS_INFORMATION) As Long
  41.  
  42. Private Declare PtrSafe Function CloseHandle Lib "kernel32" (ByVal _
  43.    hObject As Long) As Long
  44.  
  45. Private Const NORMAL_PRIORITY_CLASS = &H20&
  46. Private Const INFINITE = -1&
  47.  
  48. Public Sub ShellWait(cmdline$)
  49.    Dim proc As PROCESS_INFORMATION
  50.    Dim start As STARTUPINFO
  51.    Dim ReturnValue As Integer
  52.  
  53.    ' Initialize the STARTUPINFO structure:
  54.    With start
  55.         .cb = Len(start)
  56.         .wShowWindow = vbHide
  57.         .dwFlags = &H1&
  58.     End With
  59.    ' Start the shelled application:
  60.    ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
  61.       NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
  62.  
  63.    ' Wait for the shelled application to finish:
  64.    Do
  65.       ReturnValue = WaitForSingleObject(proc.hProcess, 0)
  66.       DoEvents
  67.       Loop Until ReturnValue <> 258
  68.  
  69.    ReturnValue = CloseHandle(proc.hProcess)
  70. End Sub
  71.  
I really don't understand what is the problem, do you think could it be the problem between access and batch file?

Best regards,
Sophanna

Attached Images
File Type: jpg 1.jpg (38.5 KB, 340 views)
Jun 5 '14 #7
twinnyfo
3,653 Expert Mod 2GB
Sophanna,

Is your button "btnFillWithNewRevision" by any chance on the Main Form and the data that shows "#Deleted" on a subform? As NeoPa said, with a Requery this is odd to see "#Deleted". However, if your data is on a subform, you may need to requery that subform:

Expand|Select|Wrap|Line Numbers
  1. Me.SubFormName.Form.Requery
That's the only thing I can think of that might help with this. Let us know if this hepps.
Jun 10 '14 #8
NeoPa
32,556 Expert Mod 16PB
Hi Sophanna.

Sorry for the long delay. I've been very busy with work commitments to the extent that I haven't visited Bytes for a week or more. Very unusual for me.

Anyway, to get to your problem, your last post (#7) states that the code used to run the batch file is in the second block of code. It seems that this is not exactly true. The code to run the batch file uses a procedure called runBat(). This is not included in the second block of code. What is included is a version of the ShellWait() Function that is different from the one I posted.

Please test the code with the posted version of the ShellWait() function to see if this is where the problem lies. I would certainly only expect to see the results you've described if the batch file had not completed by the time you run the Me.Requery code.
Jun 22 '14 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mark B | last post by:
I have a form with a subform (normal) that itself has a subform (datasheet). I can't get a delete command button to work with the following code. It says "delete not available now". Any...
1
by: Max Harvey | last post by:
Hi, I made up a nice little form which had its own sub form in it. I made a litle VB code so that when I pressed a button it would move form the form (frmConference) to the subform...
1
by: sofakingfree | last post by:
I keep getting an invalid property assignment error when tring to reference a subform. All I am trying to do is substitute this: Forms!!.SetFocus for this: FormAndSubForm.SetFocus
1
by: MP | last post by:
I have a main form that has a subform which also has a subform: the main form is the first subform is the second subform is When I click on the button »AddNewSubSubRecord« (add a new record...
1
by: dBNovice | last post by:
Please help! I have 3 forms: Task, Subtask, Elements. Elements is a subform of Subtask and Subtask is a subform of Task. I am able to navigate from Task to Subform to Element and from Element to...
4
by: bobg.rjservices | last post by:
running access 2k; adp w/ linked tables to SQL server; I am absolutely stymied, and ticked off beyond belief - I can not believe how much time I've wasted trying to do something that should be...
8
by: OldBirdman | last post by:
This should be so, so simple I hesitate to ask. I have a Form named "fNavButtons" used as a SubForm in control named "subformNavButtons". subformNavButtons is a control on my main form named...
2
by: arthur.dayton | last post by:
I am using Access 2007. I'm trying to set the control on a subform to the current time. My code is: Private Sub Command7_Click() With Me. ..Form.SetFocus ..Form!.SetFocus RunCommand...
1
by: veteranwebdesign | last post by:
Hello, I have a main form. I want forms to open in a subform control box. What is the code for the option group to open the subforms in the control box. I didn't create subforms, I created...
3
by: ckrows | last post by:
I have a main form with a button that makes a subform visible. I added a button in the form footer of the subform that is supposed to hide the subform. This does not work because the focus is on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.