I am trying to connect to mysql database a different way than usual and getting an argument not optional error on the highlighted.
FORM
VB Code:
Private Sub cmdAdd_Click() Dim LvwItm As ListItem With Me Set LvwItm = frmLedger.lvwAccountLedger.ListItems.Add(, , Format(Date, "mm/dd/yyyy")) LvwItm.SubItems(1) = .txtTransactionDescription.Text LvwItm.SubItems(2) = Format(.txtCredit.Text, "0.00") LvwItm.SubItems(3) = Format(.txtDebit.Text, "0.00") End With [hl]DatabaseConnection[/hl] strSQL = "SELECT * " strSQL = strSQL & "FROM Ledger" objCon.Execute strSQL OpenRecordset With frmLedger strSQL = "INSERT INTO Ledger (" strSQL = strSQL & "AccountNumber, " strSQL = strSQL & "TransDesc, " strSQL = strSQL & "Credit, " strSQL = strSQL & "Debit, " strSQL = strSQL & "EntryDate) " strSQL = strSQL & "VALUES (" strSQL = strSQL & "'" & .cboAccountNumber.Text & "', " strSQL = strSQL & "'" & .txtTransactionDescription.Text & "', " strSQL = strSQL & "'" & Format(.txtCredit.Text, "0.00") & "', " strSQL = strSQL & "'" & Format(.txtDebit.Text, "0.00") & "', " strSQL = strSQL & "'" & Now() & "')" End With objCon.Execute strSQL Unload Me End Sub
MODULE
VB Code:
Option Explicit Public Sub DatabaseConnection(objCon As ADODB.Connection) Set objCon = New ADODB.Connection With objCon .CursorLocation = adUseClient .ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _ & "SERVER=IP_ADDRESS;" _ & "DATABASE=DATABASE_NAME;" _ & "UID=USERNAME;" _ & "PWD=PASSWORD;" _ & "OPTIONS=3;" End With End Sub Public Sub OpenRecordset(objCon As ADODB.Connection, _ objRs As ADODB.Recordset, _ strSQL As String) Set objCon = New ADODB.Connection Set objRs = New ADODB.Recordset objCon.Open strSQL, objCon, adOpenStatic, adLockReadOnly End Sub Public Sub CloseRecordset(objRs As ADODB.Recordset) objRs.Close Set objRs = Nothing End Sub Public Sub CloseConnection(objCon As ADODB.Connection) objCon.Close Set objCon = Nothing End Sub




Reply With Quote