H
hughess7
Hi all
I am trying to create a set of data on a form by way of a recordset. The
user enters a Country and a dealer (in unbound combos) and I want the data
displayed on the form if any exists, with a count of records, OR a message
stating no data to claim if not.
I have the following code but it produces an error '2001: You cancelled the
previous operation' on the DCount line I think.
This is Part 1 of my task.
Part 2 is then to write the data found (if any) to an existing table called
[Claim Data]. The difficult part being that the fields don't match so at the
moment we use an append query to populate the table - is this possible still
somehow?
For reference, the database I am using is an inherited one and it has a lot
of pre-existing objects (tables, forms, queries, reports etc) so changing any
field names etc is not a possibility. We work in lots of different countries
throughout Europe. Each country has its own database and they are a large
file, hence combining them would not really work for Access. So each country
has its own linked Table called [Warranty Data x] x being the designated
letter(s) of that country.
I did think about using 'insert into' to write the data to a generic table
called Warranty Data and then still using the existing append queries we
have. Just not sure if this is the best / most efficient way of doing it?
--------------------------
Code:
Private Sub Dealer_AfterUpdate()
Dim NextAudit, MyTable As String
Dim txtCountry As String, txtDealer As String, MyDate As Date
Dim db As DAO.Database
Dim strSQL As String
Dim strWhere As String
NextAudit = DLookup("MaxofAuditNo", "[qry AuditNos EGP]", "[DealerCode]=" &
"""" & Me![Dealer] & """")
If IsNull(NextAudit) Then
Me![AuditNo] = 1
Else
Me![AuditNo] = NextAudit + 1
End If
txtCountry = Me![CountryCode]
txtDealer = Me![Dealer]
MyDate = Date - 1100
MyTable = "Warranty Data " & txtCountry
strSQL = "SELECT MyTable.* FROM MyTable "
strWhere = "MyTable.Dealer_Code=" & """" & txtDealer & """"
strWhere = strWhere & " AND " & "MyTable.SBI_Date>#" & MyDate & "#"
If DCount("*", MyTable, strWhere) = 0 Then
MsgBox "No records that match the chosen criteria.", vbExclamation,
"Note"
Me![ClaimData].Enabled = False
Else
Me.RecordSource = strSQL & strWhere
Me![ClaimData].Enabled = True
End If
End Sub
Thanks in advance for any help.
Sue
I am trying to create a set of data on a form by way of a recordset. The
user enters a Country and a dealer (in unbound combos) and I want the data
displayed on the form if any exists, with a count of records, OR a message
stating no data to claim if not.
I have the following code but it produces an error '2001: You cancelled the
previous operation' on the DCount line I think.
This is Part 1 of my task.
Part 2 is then to write the data found (if any) to an existing table called
[Claim Data]. The difficult part being that the fields don't match so at the
moment we use an append query to populate the table - is this possible still
somehow?
For reference, the database I am using is an inherited one and it has a lot
of pre-existing objects (tables, forms, queries, reports etc) so changing any
field names etc is not a possibility. We work in lots of different countries
throughout Europe. Each country has its own database and they are a large
file, hence combining them would not really work for Access. So each country
has its own linked Table called [Warranty Data x] x being the designated
letter(s) of that country.
I did think about using 'insert into' to write the data to a generic table
called Warranty Data and then still using the existing append queries we
have. Just not sure if this is the best / most efficient way of doing it?
--------------------------
Code:
Private Sub Dealer_AfterUpdate()
Dim NextAudit, MyTable As String
Dim txtCountry As String, txtDealer As String, MyDate As Date
Dim db As DAO.Database
Dim strSQL As String
Dim strWhere As String
NextAudit = DLookup("MaxofAuditNo", "[qry AuditNos EGP]", "[DealerCode]=" &
"""" & Me![Dealer] & """")
If IsNull(NextAudit) Then
Me![AuditNo] = 1
Else
Me![AuditNo] = NextAudit + 1
End If
txtCountry = Me![CountryCode]
txtDealer = Me![Dealer]
MyDate = Date - 1100
MyTable = "Warranty Data " & txtCountry
strSQL = "SELECT MyTable.* FROM MyTable "
strWhere = "MyTable.Dealer_Code=" & """" & txtDealer & """"
strWhere = strWhere & " AND " & "MyTable.SBI_Date>#" & MyDate & "#"
If DCount("*", MyTable, strWhere) = 0 Then
MsgBox "No records that match the chosen criteria.", vbExclamation,
"Note"
Me![ClaimData].Enabled = False
Else
Me.RecordSource = strSQL & strWhere
Me![ClaimData].Enabled = True
End If
End Sub
Thanks in advance for any help.
Sue