Thanks for all your previous help. I have finished with Excel and Word
and am now looking at Access.
I have the following working......Open a Access application, Open its
table, GoToRecord() (In this case Number, Previous and Next - for demo
purposes), but I am now stuck with FindRecord(). I use the same syntax
as GoToRecord() (I.e. I use DoCmd) but it fails to jump to the found
item. It does not give any errors but it does not give a result either!
Can you help?
Also. I was looking at ADO.C but don`t like the "Get info from excel"
scenario.....Is it possible to convert ado.c to read from a Access
file instead?....if so, could you show me a small example.
With regards to COM in general, How do I detect if a user
has closed WORD fopr example?....so I do not get any error
due to the application (WORD) no longer being available?
Regards
John
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
>> Also. I was looking at ADO.C but don`t like the "Get info from excel" scenario.....Is it possible to convert ado.c to read from a Access file instead?....if so, could you show me a small example. <<
Yes. It is quite straight forward. First you have to change the connection string slightly. You can find a list of connection strings at http://www.connectionstrings.com/. For access, this is an appropriate connection string:
/* Connect to the data source */
HR_TRY( dhCallMethod(conn, L".Open(%S)", L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MYDB.MDB;") );
/* Execute a select statement to retrieve a recordset */
HR_TRY( dhGetValue(L"%o", &rs, conn, L".Execute(%S)", L"SELECT ID, Species, Population, Status FROM [Whales] ORDER BY ID") );
_______________________________________________________________
I'm looking at your other issues now.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
>> With regards to COM in general, How do I detect if a user has closed WORD fopr example?....so I do not get any error due to the application (WORD) no longer being available? <<
I don't know any way of doing this other than calling a method and catching the error.
I posted a sample of catching a specific error in the NULLs in database thread (http://sourceforge.net/forum/forum.php?thread_id=1162124&forum_id=382149)
The specific error is usually HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE).
If you need to do regular polling, you should be able to find a property to call which won't effect the object.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
>> but I am now stuck with FindRecord(). I use the same syntax as GoToRecord() (I.e. I use DoCmd) but it fails to jump to the found item. It does not give any errors but it does not give a result either! Can you help? <<
Not really! Having a look at the default options (http://www.blueclaw-db.com/docmd_findrecord_example.htm) I notice that only the current field is searched. Could this be the problem?
Several other people seem to have had problems with FindRecord(). You could try looking through a few of the Google results (http://www.google.com/search?&q=DoCmd.FindRecord)
Good luck, sorry I couldn't be of more help on this one.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
>> With regards to COM in general, How do I detect if a user has closed WORD fopr example?....so I do not get any error due to the application (WORD) no longer being available? <<
This seems to work
dhToggleExceptions(FALSE);
dhGetObject(NULL, L"Word.Application", &wdApp);
dhToggleExceptions(TRUE);
//if (wdApp) then Word is running
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Got FindRecord() working......it was the last parameter that was needed. It also should of been
acAll and not the default acCurrent.....otherwise it would look at the current entry.
Q) How do I get a value (text) from each cell in the
access db? I tried Access.TextBox.Text but an error appears stating this object is not supported
when object browser clearly states access.textbox.
Anyway. Is there a way to get the text. Also how would you use SetFocus. I.e. what am I looking for to set the focus on......textbox (no!)????
If I change the ado header to access rather than
excel, as you say previously, does this mean I just
use the other (excel) commands the same way for access or are there variations?
Regards
John
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
>> Q) How do I get a value (text) from each cell in the access db? I tried Access.TextBox.Text but an error appears stating this object is not supported when object browser clearly states access.textbox. Anyway. Is there a way to get the text. Also how would you use SetFocus. I.e. what am I looking for to set the focus on......textbox (no!)???? <<
/* Hopefully, retrieves the value of the currently selected field. */
dhGetValue(L"%s", &szValue, acApp, L".Screen.ActiveControl.Value");
_______________________________________________________________
/* Should set the focus on the desired control. */
dhCallMethod(acApp, L".Forms(%s).Controls(%s).SetFocus()", "Employees", "EmployeeID");
_______________________________________________________________
>> If I change the ado header to access rather than excel, as you say previously, does this mean I just use the other (excel) commands the same way for access or are there variations? <<
Yes, the SQL commands for Access and Excel are very similar as they use the same JET database provider. SQL commands for a different database provider such as MySQL would be significantly different.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi XTMouse,
Thanks for all your previous help. I have finished with Excel and Word
and am now looking at Access.
I have the following working......Open a Access application, Open its
table, GoToRecord() (In this case Number, Previous and Next - for demo
purposes), but I am now stuck with FindRecord(). I use the same syntax
as GoToRecord() (I.e. I use DoCmd) but it fails to jump to the found
item. It does not give any errors but it does not give a result either!
Can you help?
Also. I was looking at ADO.C but don`t like the "Get info from excel"
scenario.....Is it possible to convert ado.c to read from a Access
file instead?....if so, could you show me a small example.
dhCreateObject(L"Access.Application",NULL,&adApp);
dhPutValue(adApp,L".Visible = %b",TRUE);
dhCallMethod(adApp,L".OpenCurrentDatabase(%s)","filename");
dhCallMethod(adApp,L".DoCmd.OpenTable(%s)","tablename");
dhCallMethod(adApp,L".DoCmd.GoToRecord(%d,%s,%d,%d)",0,tname,4,number);
dhCallMethod(adApp,L".DoCmd.GoToRecord(%d,%s,%d)",0,"tablename",0);
dhCallMethod(adApp,L".DoCmd.GoToRecord(%d,%s,%d)",0,"tablename",1);
// Not working....
dhCallMethod(adApp,L".DoCmd.FindRecord(%s)",textString);
dhCallMethod(adApp,L".CloseCurrentDatabase"); //.Quit");
With regards to COM in general, How do I detect if a user
has closed WORD fopr example?....so I do not get any error
due to the application (WORD) no longer being available?
Regards
John
>> Also. I was looking at ADO.C but don`t like the "Get info from excel" scenario.....Is it possible to convert ado.c to read from a Access file instead?....if so, could you show me a small example. <<
Yes. It is quite straight forward. First you have to change the connection string slightly. You can find a list of connection strings at http://www.connectionstrings.com/. For access, this is an appropriate connection string:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;"
Secondly, Access tables do not end with a $ symbol.
So, for the AdoRead sample, you would change the following two lines:
_______________________________________________________________
/* Connect to the data source */
HR_TRY( dhCallMethod(conn, L".Open(%S)", L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MYDB.MDB;") );
/* Execute a select statement to retrieve a recordset */
HR_TRY( dhGetValue(L"%o", &rs, conn, L".Execute(%S)", L"SELECT ID, Species, Population, Status FROM [Whales] ORDER BY ID") );
_______________________________________________________________
I'm looking at your other issues now.
>> With regards to COM in general, How do I detect if a user has closed WORD fopr example?....so I do not get any error due to the application (WORD) no longer being available? <<
I don't know any way of doing this other than calling a method and catching the error.
I posted a sample of catching a specific error in the NULLs in database thread (http://sourceforge.net/forum/forum.php?thread_id=1162124&forum_id=382149)
The specific error is usually HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE).
If you need to do regular polling, you should be able to find a property to call which won't effect the object.
>> but I am now stuck with FindRecord(). I use the same syntax as GoToRecord() (I.e. I use DoCmd) but it fails to jump to the found item. It does not give any errors but it does not give a result either! Can you help? <<
Not really! Having a look at the default options (http://www.blueclaw-db.com/docmd_findrecord_example.htm) I notice that only the current field is searched. Could this be the problem?
Several other people seem to have had problems with FindRecord(). You could try looking through a few of the Google results (http://www.google.com/search?&q=DoCmd.FindRecord)
Good luck, sorry I couldn't be of more help on this one.
>> With regards to COM in general, How do I detect if a user has closed WORD fopr example?....so I do not get any error due to the application (WORD) no longer being available? <<
This seems to work
dhToggleExceptions(FALSE);
dhGetObject(NULL, L"Word.Application", &wdApp);
dhToggleExceptions(TRUE);
//if (wdApp) then Word is running
Yes, that will work for dhGetObject(). However, if Word is closed later on, an error will be triggered when you call a property or method.
Your approach with dhGetObject() is also demonstrated in dexplore.c.
Hi XTMouse,
Got FindRecord() working......it was the last parameter that was needed. It also should of been
acAll and not the default acCurrent.....otherwise it would look at the current entry.
Q) How do I get a value (text) from each cell in the
access db? I tried Access.TextBox.Text but an error appears stating this object is not supported
when object browser clearly states access.textbox.
Anyway. Is there a way to get the text. Also how would you use SetFocus. I.e. what am I looking for to set the focus on......textbox (no!)????
If I change the ado header to access rather than
excel, as you say previously, does this mean I just
use the other (excel) commands the same way for access or are there variations?
Regards
John
>> Q) How do I get a value (text) from each cell in the access db? I tried Access.TextBox.Text but an error appears stating this object is not supported when object browser clearly states access.textbox. Anyway. Is there a way to get the text. Also how would you use SetFocus. I.e. what am I looking for to set the focus on......textbox (no!)???? <<
I'm not too much help on this one. I don't have Access installed on this computer and therefore I am going off the documentation I found here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acobjApplication.asp
You could try something like this:
_______________________________________________________________
/* Hopefully, retrieves the value of the currently selected field. */
dhGetValue(L"%s", &szValue, acApp, L".Screen.ActiveControl.Value");
_______________________________________________________________
I found documentation for the SetFocus() method here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acmthSetFocus.asp
To set the focus to the EmployeeID field control on the Employees form, I think you would use something like this:
_______________________________________________________________
/* Should set the focus on the desired control. */
dhCallMethod(acApp, L".Forms(%s).Controls(%s).SetFocus()", "Employees", "EmployeeID");
_______________________________________________________________
>> If I change the ado header to access rather than excel, as you say previously, does this mean I just use the other (excel) commands the same way for access or are there variations? <<
Yes, the SQL commands for Access and Excel are very similar as they use the same JET database provider. SQL commands for a different database provider such as MySQL would be significantly different.
Thanks XTMouse,
They worked fine.
Regards
John