Hello bright people,
I have set up a macro that takes a file name or web link from a column called “URL” in a subform called “URLForm” and puts that string into a button’s Target URL field.
This works fine for existing records. However when I create a new record in the parent form “MainForm”, there is no record in the column field called “URL” in the subform “URLForm” so my macro breaks at the line:
stCol = oform.Columns.getbyname("URL").getstring
I get an error:
BASIC runtime error.
An exception occurred
Type: com.sun.star.sdbc.SQLException
Message: The cursor points to before the first or after the last row..
I have not been able to work out the condition to use in an IF statement to end the sub if there is no record present in the subform “URLForm”.
Thank you very much for your help.
I am using:
Version: 7.2.5.2 (x64) / LibreOffice Community
Build ID: 499f9727c189e6ef3471021d6132d4c694f357e5
CPU threads: 4; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: en-GB (en_GB); UI: en-GB
Calc: threaded
Here is the macro:
SUB InsertLocation
Dim oForm as Object
Dim oButton as Object
Dim oSubstService as Object
Dim stHomePath as String
Dim stFullPath as String
Dim stDrive as String
Dim stStart as String
Dim stCol as String
oForm = thiscomponent.drawpage.forms.getbyname("MainForm").getByName("URLForm")
oButton = oform.btnGetURL
oButton.TargetUrl = ""
oSubstService = CreateUnoService("com.sun.star.util.PathSubstitution")
stHomePath = oSubstService.substituteVariables("$(prog)", true)
stDrive = Mid(stHomePath, 9,1)
IF stDrive = "C" THEN
stFullPath = "file:///C:/Users/PS/Nextcloud/Documents/OwnFiles/Clinical/Useful info/"
ELSE
stFullPath = "file:///" + stDrive + ":/nc/Documents/Ownfiles/Clinical/Useful info/"
END IF
stCol = oform.Columns.getbyname("URL").getstring
stStart = Left(stCol, 3)
IF stStart <> "" THEN
IF stStart = "htt" OR stStart = "www" THEN
oButton.TargetUrl = oform.Columns.getbyname("URL").getstring
ELSE
oButton.TargetUrl = stFullPath + oform.Columns.getbyname("URL").getstring
END IF
END IF
END SUB