I have some utility functions which allow me to save Access form location for a pop-up form when it is closed, and later when opened it will be moved to that location. In Form_Close event I call this method:
Code:
Public Function SaveFormPosition(formName As String) As Boolean
Const REG_DWORD = 4
Dim regKey As String
If Forms(formName).windowLeft < 0 Then
Forms(formName).Move 0, Forms(formName).windowTop
End If
If Forms(formName).windowTop < 0 Then
Forms(formName).Move Forms(formName).windowLeft, 0
End If
If oRegistry Is Nothing Then Call GetObjects
With oRegistry
regKey = TempVars!UserSettingsRegPath & formName & "_XPos"
.REG_ADD .GetRegPath(regKey), .GetSubKey(regKey), Forms(formName).windowLeft, REG_DWORD
regKey = TempVars!UserSettingsRegPath & formName & "_YPos"
.REG_ADD .GetRegPath(regKey), .GetSubKey(regKey), Forms(formName).windowTop, REG_DWORD
End With
End Function
oRegistry is a class object to handle registry interaction. I was encountering issues with using Windows API to write registry keys, so I'm using REG.EXE to write the key value as follows:
Code:
Public Function REG_ADD(ByVal regKey As String, valueName As String, newValue As String, Optional valueType As KeyTypeEnum = KeyTypeEnum.REG_SZ) As Boolean
Dim valTypeName As String
Dim cmd As String
Dim result As Double
Dim newVal As Variant
'Shorten root key name if needed.
regKey = shorten_reg_key_root(regKey)
'Get text name of value type.
valTypeName = reg_val_type_name(valueType)
'Build command line for REG.EXE.
cmd = "REG ADD """ & regKey & """ /f /v """ & valueName & """ /t " & valTypeName & " /d " & newValue
result = Shell(cmd, vbHide)
REG_ADD = (result <> 0)
End Function
I decided I want to move the form a bit higher on the screen, into the ribbon area and save the negative Y position in the registry. So I commented out the second Move command in the first method above, hoping that the negative Y position would be saved in the registry. Unfortunately, when I look in the registry, the value gets saved as 0.
I put a break point in and polled the value of "cmd", and it looks like:
Code:
REG ADD "HKEY_CURRENT_USER\Software\FedConnect\User Settings" /f /v "ImportExportSettings_YPos" /t REG_DWORD /d -1008
So what am I doing wrong here? The negative number is getting replaced with 0 when it is written to the registry, or else the registry doesn't allow a negative DWORD value.
Do I instead need to convert the decimal X & Y positions to HEX and play with the first hex digit to get it to go negative? Can't exactly remember how to do that.
Thanks...