Call function in VBA (Access 2007)
-
Dear developers, I have problem in calling function from module in access 2007. 1. Let's see my code: Public Function insertDB(tblName As String, tblField As String, strValue As String, db As ADODB.Database) Dim Str As String Dim Rst As New ADODB.Recordset Rst.CursorLocation = adUseClient Str = "Insert into" & tblName & "(& tblField &)" & " Values(" & strValue & ")" db.Execute Str End Function Is it the correct function??? 2. How to call this function in the form?? Cheers, Visoth
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
-
Dear developers, I have problem in calling function from module in access 2007. 1. Let's see my code: Public Function insertDB(tblName As String, tblField As String, strValue As String, db As ADODB.Database) Dim Str As String Dim Rst As New ADODB.Recordset Rst.CursorLocation = adUseClient Str = "Insert into" & tblName & "(& tblField &)" & " Values(" & strValue & ")" db.Execute Str End Function Is it the correct function??? 2. How to call this function in the form?? Cheers, Visoth
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
It's close to being right...
misCafe wrote:
Str = "Insert into" & tblName & "(& tblField &)" & " Values(" & strValue & ")"
Should be: Str = "Insert into" & tblName & " (" & tblField ") Values(" & strValue ")" Of course, this method needs a little more looking at, as you will need to ensure that your strValue parameter includes single quotes around the string you are inserting (if it's a string). You would call this function from the form perhaps via the On Click event of a button.
I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!
-
Dear developers, I have problem in calling function from module in access 2007. 1. Let's see my code: Public Function insertDB(tblName As String, tblField As String, strValue As String, db As ADODB.Database) Dim Str As String Dim Rst As New ADODB.Recordset Rst.CursorLocation = adUseClient Str = "Insert into" & tblName & "(& tblField &)" & " Values(" & strValue & ")" db.Execute Str End Function Is it the correct function??? 2. How to call this function in the form?? Cheers, Visoth
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
The function does not actually return anything and therefore should be a sub rather than a functions
Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.
-
The function does not actually return anything and therefore should be a sub rather than a functions
Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.