I have a large medical database. Several computers with front ends on each. One back end on a sever. The procedure has several action SQR statements.
My problem is that on occasion, apparently at whim, one SQL statement is not executed.
I know that this description may lack clues, but I wonder if there are any inkling out there on what could be the issue.
Thanks for any ideas.
Louis
The following is the code. As I have said most of the time it works fine. Sometimes, I don’t know when and why, it fails to execute the part of the code marked in block letters. I suspect it is because of the connection with the server. This is slow at times.
Private Sub Command20_Click()
If IsNull(Me.Frame22) Then
MsgBox "Please indicate a choice from the list!"
Exit Sub
Else
End If
'Set mydb = CurrentDb()
'Set rst1 = mydb.OpenRecordset("tblInvoices", dbOpenDynaset)
'Set mydb = CurrentDb()
'Set rst1 = mydb.OpenRecordset("tblInvoices", dbOpenDynaset)
'rst1.AddNew
'rst1.InvAmount = Forms!frmBilling!Text12
'rst1.InvDate = Date
'rst1.Invoiced = True
'rst1.PayDate = Date
'rst1.CltID = Forms!frmBilling!List0.Column(0)
'rst1.UserNameInv = Forms!FrmMain!TxtIdentifier
'rst1.Paid = True
'rst1.methodofpayment = Me.Frame22
'Forms!frmBilling!paste_invoiceno = rst1!InvoiceNo
'rst1.Update
'rst1.Close
'Set rst1 = Nothing
'Set mydb = Nothing
'the above code was how it was before.
DoCmd.SetWarnings False
StrSQL = "INSERT INTO tblInvoices ( InvAmount, InvDate, Invoiced, PayDate, CltID, UserNameInv, Paid, methodofpayment )" _
& "SELECT [Forms]![frmBilling]![Text12] AS Expr1, Date() AS Expr2, True AS Expr3, Date() AS Expr4, [Forms]![frmBilling]![List0] AS Expr5, [Forms]![FrmMain]![TxtIdentifier] AS Expr6, True AS Expr7, [Forms]![FrmMethodofPaymentB]![Frame22] AS Expr8;"
DoCmd.RunSQL StrSQL
Forms!frmBilling!paste_invoiceno = DMax("InvoiceNo", "tblInvoices")
Dim lista As String
lista = Forms!frmBilling!List0.Column(0) 'takes up the idcard number
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you want to print this invoice ?" & vbCrLf & " Please check that you have a letterhead in the printer!"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "MsgBox Demonstration"
Help = "DEMO.HLP"
Ctxt = 1000
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbNo Then ' User chose no.
Else
DoCmd.OpenReport "RptInvoicefromfrmBilling", acViewNormal, , , acWindowNormal
'DoCmd.OpenReport "RptInvoicefromfrmBilling", acViewNormal, , , acWindowNormal 'second copy
DoCmd.Close acReport, "RptInvoicefromfrmBilling", acSaveNo
End If
DoCmd.Close acForm, "FrmMethodofPaymentB", acSaveNo
'apparently one should not reference controls from reports. it took me ages to fix these SQL statements. I had to reference on the forms rather than the reports.
' i do not know how the ones in dbSerena worked. In dbserena it worked!
'marks the tblservicelog as invoiced and adds invoice no
StrSQL = "UPDATE tblservicelog SET tblservicelog.invoiceno =[Forms]![frmBilling]![paste_invoiceno] , tblservicelog.invoiced = true, tblservicelog.paid = true" _
& " WHERE (((tblservicelog.invoiced)=false) AND ((tblservicelog.hospno)='" & lista & "')AND ((tblservicelog.include)=True));"
DoCmd.RunSQL StrSQL
'marks the tblHospitalisations as invoiced and add invoice no
StrSQL = "UPDATE tblHospitalisations SET tblHospitalisations.invoiced = Yes, tblHospitalisations.paid = yes, tblHospitalisations.InvoiceNo = [Forms]![frmBilling]![paste_invoiceno]" _
& " WHERE (((tblHospitalisations.cltIdcard)= '" & lista & "') AND (Not (tblHospitalisations.DateDischarge) Is Null) AND ((tblHospitalisations.invoiced)=No));"
DoCmd.RunSQL StrSQL
'marks those investigations that are to be billed with invoice no, invoiced and paid.
StrSQL = "UPDATE tblTest INNER JOIN tblClinPict ON tblTest.IDClinPict = tblClinPict.ID SET tblTest.Invoiceno = [Forms]![frmBilling]![paste_invoiceno], tblTest.Invoiced = true, tblTest.paid = true" _
& " WHERE (((tblTest.Invoiced)=False) AND ((tblTest.Status)='collected') AND ((tblClinPict.CltID)='" & lista & "') AND ((tblTest.tobebilled)=True)) OR (((tblTest.Invoiced)=False) AND ((tblTest.Status)='Printed') AND ((tblClinPict.CltID)='" & lista & "') AND ((tblTest.tobebilled)=True));"
DoCmd.RunSQL StrSQL
'marks those investigations that are NOT to be billed with invoice no, not invoiced and not paid.
StrSQL = "UPDATE tblTest INNER JOIN tblClinPict ON tblTest.IDClinPict = tblClinPict.ID SET tblTest.Invoiceno = [Forms]![frmBilling]![paste_invoiceno], tblTest.Invoiced = false, tblTest.paid = false" _
& " WHERE (((tblTest.Invoiced)=False) AND ((tblTest.Status)='collected') AND ((tblClinPict.CltID)='" & lista & "') AND ((tblTest.tobebilled)=True)) OR (((tblTest.Invoiced)=False) AND ((tblTest.Status)='Printed') AND ((tblClinPict.CltID)='" & lista & "') AND ((tblTest.tobebilled)=false));"
DoCmd.RunSQL StrSQL
'marks the tblConsumables to be billed as invoiced, paid and adds invoicno
StrSQL = "UPDATE tblConsumables SET tblConsumables.invoiceno = [Forms]![frmBilling]![paste_invoiceno], tblConsumables.invoiced = true, tblConsumables.paid = true" _
& " WHERE (((tblConsumables.invoiceno)=0) AND ((tblConsumables.IDcardNo)='" & lista & "') AND ((tblConsumables.tobebilled)=Yes));"
'DoCmd.RunSQL StrSQL
'marks the tblConsumables which are not to be billed as NOT invoiced, NOT paid but with the inv no.
StrSQL = "UPDATE tblConsumables SET tblConsumables.invoiceno = [Forms]![frmBilling]![paste_invoiceno], tblConsumables.invoiced = false, tblConsumables.paid = false" _
& " WHERE (((tblConsumables.invoiceno)=0) AND ((tblConsumables.IDcardNo)='" & lista & "') AND ((tblConsumables.tobebilled)=No));"
'DoCmd.RunSQL StrSQL
'------------------------------------------------------------------------------------------------------------
'strSQL = "SELECT * FROM Orders WHERE ShipCity = """ & Me!txtShipCity & """"
' the above how to insert a text reference into a SQL statment
'SQL = "select partno, description from Inventory where partno = '" & part & "'"
'-----------------------------------------------------------------------------------------------------------------
'how to include variables in an SQL statement
'String variables would take the form:
'SQL = "select partno, description from Inventory where partno = '" & part & "'"
'where the single quote begins the string value, then the sql variable is stopped and the variable containing the value is appended, then the final single quote is appended to the sql variable.
'For numeric variables just leave off the single quotes:
'SQL = "select partno, description from Inventory where partno = " & part & "
'For Microsoft Access Date types replace the single quote with a # (hash) mark.
'For substituting the values in RFgen prompts without declaring variables:
'SQL = "select partno, description from Inventory where partno = '%part'"
'RFgen will search and replace the text %part and replace it with the value in that prompt's textbox. Again, if it should be numeric, just leave off the single quotes.
'To reference a prompt by number instead of name (in case of a loop structure):
'SQL = "select partno, description from Inventory where partno = '%3'"
'===========================================================================================================
DoCmd.SetWarnings True
DoCmd.Close acForm, "frmBilling", acSaveYes ' requery not working
DoCmd.OpenForm "frmBilling", acNormal
Forms!frmBilling.List0 = Null
End Sub