I’m calling a method that returns a true or false value if there has been a database error see below:
Public Function AddURLRow(URL As String, comment As String) as Boolean
// Add a row to the url table
If Not IsConnected Then
MsgBox(“Create the database and create the table first.”)
Return False
End If
Dim d as new date
Dim row As New DatabaseRecord
// ID will be added automatically
row.Column(“url”) =url
row.Column(“comment”) = comment
row.Column(“datechange”) = str(d)
App.DB.InsertRecord(“urldata”, row)
If App.DB.Error Then
MsgBox( "DB Error: " + App.DB.ErrorMessage)
Return False
End If
//Return True
End Function
here is the calling code:
Dim d as new date
Dim row As New DatabaseRecord
// ID will be added automatically
row.Column(“url”) =url
row.Column(“comment”) = comment
row.Column(“datechange”) = str(d)
App.DB.InsertRecord("urldata", row)
If Not App.DB.Error then
MsgBox("Record Added")
return
End if
I keep getting the error message:URLManager.AddButton Action line 46, you must use the value returned by the function.
Can somone please explain to me why I’m getting this message as it seems to me I am using the returned value App.DB.Error.
I’m just trying to set a variable to he current date and time and it Is not clear to me how d.sqldatetime works: the following code throws type mismatch errors:
Dim d as new date
d =d.SQLdatetime
row.Column("datechange") = d.SQLDateTime
One problem with your code is that AddURLRow doesn’t return anything useful. It either returns False, or it returns nothing (which is the default value of False). You have 2 options:
1 - In AddURLRow, return App.DB.Error (or at least return TRUE in your if App.DB.Error Then block). And change your calling code to
if AddURLRow(url,comment) then
MsgBox("Record Added")
return
End if
2 - Remove the return value from AddURLRow
3 - Change AddURLRow such that it returns TRUE on success and FALSE on failure. Modify the code in 1), above, appropriately.
[quote=314229:@Delbert Thompson]I’m just trying to set a variable to he current date and time and it Is not clear to me how d.sqldatetime works: the following code throws type mismatch errors:
Dim d as new date
d =d.SQLdatetime
row.Column("datechange") = d.SQLDateTime[/quote]
Use
Dim d as new date
row.Column("datechange") = d.SQLDateTime
Thank you for your replies. Your suggestions have everything working now. Would you be able to recommend a good XoJo for dummies books that would take me through building a database application?