Access 2016 - api functions

lana

Registered User.
Local time
Today, 16:53
Joined
Feb 10, 2010
Messages
92
Hello there,


I have used Windows API functions in access 2016 on Windows 10. I used the correct format for 64bit.

It works fine in one computer but gives me "Type mismatch error" on another computer with Windows 10 and also Access 2016?


Any help would be appreciated.


Thanks a lot.
 
did you try with the PTRSAFE ?

Declare PtrSafe Function MyMathFunc Lib "User32" (ByVal N As LongLong) As Long
 
Yes.
It works fine without error in one computer (Win10, Access 2016).



On another computer with Win10 and Access 2016 gives me this "Type mismatch error"???
 
Is the "bitness" the same on the working and non-working systems? Not only Windows but also Office.

Another factor to consider is that your references are a function of the registry, which is not the same from computer A to computer B. So see whether the references between the two systems are the same. And I'm not necessarily talking about a reference to the WinAPI module itself, which is often late-bound anyway. I have seen a few cases where I saw the type mismatch on some call, and it was caused by a missing reference to something else entirely unrelated to the failing call. Can't tell you why, but I've seen it.
 
I would use longptr instead of long long as one could be running office 32 bit
 
Hello there,


Many thanks for the replies.


I changed all the LongPtr to LongLong and error disappeared BUT...


At the beginning of my code I used these functions :


hDC = apiGetDC(hWndAccessApp)
XPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSX)
YPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSY)
lngRetVal = apiReleaseDC(hWndAccessApp, hDC)



The strange thing is : the returned numbers are

hDC =1593903413^
XPIXELSPERINCH = 96^
YPIXELSPERINCH = 96^
lngRetVal= 1^



I don't understand why ^ appears at the end of the numbers???
because of this the rest of my code does not work.


Any ideas??
Really appreciate any help.
Cheers
 
Where do you see those answers with carets? They are indicative of the data type of the variable. I suspect that you are getting LongLong returns from the functions you called, but I've lost track of the page that explains the various formatting symbols.

In any case, if you wanted them in another format, I think you can just use a conversion functions on everything that SHOULD just be an integer. However, your hDC might not be "just" an integer so I would be careful with it.
 
Last edited:
As has already been mentioned, using LongLong is unhelpful as your code will then not run in 32-bit Access

LongPtr has been designed so it will work in both 'bitnesses' for Access 2010 and later
 
Hello,

Thanks for the replies.

My code works in one computer with Win10, access 2016 but I have this problem in another computer.

My code is calculating the co-ordinates of a text box and moves a form there like a DatePicker.

Dim hDC As LongLong, lngRetVal As LongLong

hDC = apiGetDC(hWndAccessApp)
XPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSX)
YPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSY)
lngRetVal = apiReleaseDC(hWndAccessApp, hDC)

'''''''''''''''''''''''''''''''''''''''''''''''''''

Dim hWndTextBox As LongLong, rectTextBox As RECT_Type
Dim hWndMDIClient As LongLong, rectMDIClient As RECT_Type

Forms(aa).Controls(bb).SetFocus
hWndTextBox = apiGetFocus()
lngRetVal = apiGetWindowRect(hWndTextBox, rectTextBox)
hWndMDIClient = apiFindWindowEx(hWndAccessApp, 0, "MDIClient", vbNullString)
lngRetVal = apiGetWindowRect(hWndMDIClient, rectMDIClient)

' Make metrics relative to the MDIClient window
With rectTextBox
.Bottom = .Bottom - rectMDIClient.Top - apiGetSystemMetrics(SM_CYBORDER)
.Left = .Left - rectMDIClient.Left - apiGetSystemMetrics(SM_CXBORDER)
.Right = .Right - rectMDIClient.Left - apiGetSystemMetrics(SM_CXBORDER)
.Top = .Top - rectMDIClient.Top - apiGetSystemMetrics(SM_CYBORDER)
End With

' Convert the measurements from pixels to twips.
With rectTextBox
.Bottom = .Bottom * (TWIPSPERINCH / XPIXELSPERINCH)
.Left = .Left * (TWIPSPERINCH / XPIXELSPERINCH)
.Right = .Right * (TWIPSPERINCH / XPIXELSPERINCH)
.Top = .Top * (TWIPSPERINCH / XPIXELSPERINCH)
End With

Me.Move Left:=rectTextBox.Left, Top:=rectTextBox.Bottom




hWndAccessApp returns 66578 on the computer which works and returns 328548 on the other.

?????
 
Thanks.


I can not use simple move method.


If a text box (anywhere on the form) is double clicked, a specific form must be opened exactly below that text box.
The co-ordinates of the text box relative to the screen is needed (not relative to the form).


My code works fine for access 2003 and also on 2016 in one of my laptops. The new one with access 2016 gives this problem.
 
hWndAccessApp returns 66578 on the computer which works and returns 328548 on the other.

Yes. If those are "window handles" (as the nomenclature seems to indicate) then they are actually internal addresses of a structure. The "handle" is like a pointer, and you can run the same code twice on the same computer, time-shifted a little, and STILL get different handles. Whenever you see "hWnd" as the prefix, that is a window handle and you NEVER modify it. Nor can you make sense out if it. It's just a pointer to something for which the location is not predictable. You CANNOT assign ANY significance to the fact that they differ.
 
Slightly trickier BUT you still don't need to use an API.
The attached example has 2 forms: Form 1 & Form2
Form1 - has 2 textboxes and an orange rectangle
Double click either textbox - Form2 will open/move directly below that textbox
The orange box will also move - directly below the other textbox

Try moving Form1 on the screen or its controls within the form.
It should still work

Hopefully the code is understandable - its only a few lines
Ask if its not clear

For info, I use this idea for a custom zoom box where there is too much test to fit the textbox.
Double click a control and the zoombox form opens directly below it!
 

Attachments

Thanks so much. I will try your suggestion. It's appears to be much simpler. Thanks again. Cheers
 
I've nothing against the use of APIs and use them where they provide the best or at times only solution.

My approach here is definitely much simpler and more importantly I believe it will work on any workstation.

Good luck.
 
Last edited:
Thanks so much.


I tried your suggestion and it works fine for a text box on a form but when I use it on a sub form ....


There is a sub form on the main form. There is a field in the sub form which I need to put the code on it's double click event. When I do that the co-ordinates of the opened form is the co-ordinates of the text box on the sub form in its form view not on its datasheet view.


Any ideas?
 
I'm only half awake.
So I'm sure I'm understanding correctly, please can you post a screenshot.
 
Hi lana

AFAIK it can't be done with a datasheet.
As you said, the popup form moves to the design view control position

That's because the datasheet controls are actually where they are located in design view but 'trickery' is used to layout the form controls as they appear on screen

BUT the good news is it can be done with a continuous form ... which can be made to look/behave almost like a datasheet anyway.

New version attached with additional forms.
a) Form1 - single form as in previous version
b) Form 2 - continuous
c) Form 3 - with Form 2 as continuous subform

The other form is now called frmZoom and shows how it can be used to display the contents of the clicked textbox

Hope that helps
 

Attachments

Further update to version 3. Improvements include:
1. The previous version was intended for use with overlapping windows only
I've now modified the code & forms so it now works using tabbed documents as well
2. The previous version placed the zoom box with reference to the autonumber ID field.
Of course if the numbers aren't continuous due to deleted records that will 'go wrong'
This version instead uses a Serialize function to get the rank order or 'record number' for the selected record
3. I've also added code to handle nulls and blank textboxes

attachment.php


It seems to work well now from my testing. Let me know what you think
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom