I've been struggling with putting together this code and have run into another problem. This whole project revolves around the fact that I have to query 3 separate linked tables to find one record. Given a claim number, the record could be in one of 3 linked tables. I have set up 3 queries. Each query pulls from one of the 3 linked tables. Depending on the format of a field, the code "decides" which query to run. The following code is behind a button on a form. The user enters various pieces of information, including [Claim#].
The code first deletes the current records from [T: Standard Claim Info for Forms], then uses an If/Else statement, based on the format of the [Claim#] field, to decide which query to run. Each of the 3 queries are append queries to the table [T: Standard Claim Info for Forms].
If the [Claim#] field falls into the If or the ElseIf statements, the appropriate queries run without error. However, if the [Claim#] field falls into the Else statement, I get the Error 3464: Datatype Mismatch error. The error falls on the qdf.Execute dbFailOnError statement in the Else section. My question is 2-fold:
1. Any suggestions on handling the 3 different linked tables differently?
2. Why am I getting the 3464 error?
Private Sub Command33_Click()
DoCmd.SetWarnings False
Dim dbs As DAO.Database
Dim strSql As String
Dim qdf As QueryDef
Set dbs = CurrentDb
strSql = "DELETE FROM [T: Standard Claim Info for Forms];"
dbs.Execute strSql, dbFailOnError
If (Me.[Claim#] Like "CB0*") Then
Set qdf = dbs.QueryDefs("Q: Standard Claim Info for Forms PC")
qdf.Execute dbFailOnError
ElseIf (Me.[Claim#] Like "CB*") And (Mid(Me.[Claim#], 3, 1) <> "0") Then
Set qdf = dbs.QueryDefs("Q: Standard Claim Info for Forms Bond")
qdf.Execute dbFailOnError
Else
Set qdf = dbs.QueryDefs("Q: Standard Claim Info for Forms")
qdf.Execute dbFailOnError
End If
DoCmd.OpenQuery "Q: Claim Information for Attorney Assignment", acViewNormal, acEdit
DoCmd.close acQuery, "Q: Claim Information for Attorney Assignment"
MergeAllWord "Attorney Assignment Letter"
DoCmd.SetWarnings True
End Sub
Thanks in advance for any help!
The code first deletes the current records from [T: Standard Claim Info for Forms], then uses an If/Else statement, based on the format of the [Claim#] field, to decide which query to run. Each of the 3 queries are append queries to the table [T: Standard Claim Info for Forms].
If the [Claim#] field falls into the If or the ElseIf statements, the appropriate queries run without error. However, if the [Claim#] field falls into the Else statement, I get the Error 3464: Datatype Mismatch error. The error falls on the qdf.Execute dbFailOnError statement in the Else section. My question is 2-fold:
1. Any suggestions on handling the 3 different linked tables differently?
2. Why am I getting the 3464 error?
Private Sub Command33_Click()
DoCmd.SetWarnings False
Dim dbs As DAO.Database
Dim strSql As String
Dim qdf As QueryDef
Set dbs = CurrentDb
strSql = "DELETE FROM [T: Standard Claim Info for Forms];"
dbs.Execute strSql, dbFailOnError
If (Me.[Claim#] Like "CB0*") Then
Set qdf = dbs.QueryDefs("Q: Standard Claim Info for Forms PC")
qdf.Execute dbFailOnError
ElseIf (Me.[Claim#] Like "CB*") And (Mid(Me.[Claim#], 3, 1) <> "0") Then
Set qdf = dbs.QueryDefs("Q: Standard Claim Info for Forms Bond")
qdf.Execute dbFailOnError
Else
Set qdf = dbs.QueryDefs("Q: Standard Claim Info for Forms")
qdf.Execute dbFailOnError
End If
DoCmd.OpenQuery "Q: Claim Information for Attorney Assignment", acViewNormal, acEdit
DoCmd.close acQuery, "Q: Claim Information for Attorney Assignment"
MergeAllWord "Attorney Assignment Letter"
DoCmd.SetWarnings True
End Sub
Thanks in advance for any help!